I have the following table members:
ID | hobby |
---|---|
1 | Football |
1 | Tennis |
1 | Football |
2 | Cards |
2 | Painting |
3 | Tennis |
3 | Football |
4 | Cards |
and i want to select pairs of members only if they have the exact same hobbies (without duplicates). So in the table above, i want the query to output:
id1 | id2 |
---|---|
1 | 3 |
my query:
SELECT m1.id as id1 , m2.id as id2
FROM members m1 inner join members m2
ON m1.id < m2.id
WHERE m1.hobby in (
SELECT distinct(m2.hobby)
)
GROUP BY id1,id2
but i get:
id1 | id2 |
---|---|
1 | 3 |
2 | 4 |