我有一个包含 2 个字段(名称、兴趣)的表,我想找到所有具有相同兴趣的对,并删除所有重复项和镜像对。
我可以使用以下 SQL 语句找到所有对并删除重复项:
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;
但我不确定如何删除镜像对,即:
"wil","ben","databases"
"ben","wil","databases"
我试图使上述语句成为一个名为 Matches 的视图,并尝试了以下查询:
SELECT * FROM Matches
WHERE name2 <> (select name1 from Matches);
但它不会删除所有镜像对。