在SQL中组合常见值

时间:2011-10-01 07:35:22

标签: mysql sql

说实例我有下表(成员之间充满了连接)

connectionA    ConnectionB
   887             225
   129             887
   225             887
   887             562
   562             887

如何使用SQL查找A连接到B的所有行,反之亦然。查询将返回(不允许重复):

connectionA    ConnectionB
   887             225
   887             562

1 个答案:

答案 0 :(得分:3)

SELECT T1.connectionA, T1.connectionB
FROM yourtable T1
JOIN yourtable T2
ON T1.connectionA = T2.connectionB
AND T2.connectionA = T1.connectionB
WHERE T1.connectionA > T1.connectionB