I have a table with 2 fields (name, interest) and I want to find all pairs that have the same interest, with all duplicates and mirrored pairs removed.
I am able to find all pairs and remove duplicates with the following SQL statement:
SELECT P1.name AS name1, P2.name AS name2, P1.interest
FROM Table AS P1, Table AS P2
WHERE P1.interest = P2.interest AND P1.name <> P2.name;
But I am not sure how to remove mirrored pairs, ie:
"wil","ben","databases"
"ben","wil","databases"
I tried to make the above statement a view called Matches and attempted the following query:
SELECT * FROM Matches
WHERE name2 <> (select name1 from Matches);
But it does not remove all mirrored pairs.