开发者

Combining common values in SQL

Say for Instance I have the following table (full of connections between members)

connectionA    ConnectionB
   887             225
   129             887
   225             887
   887           开发者_JS百科  562
   562             887

How am I able to use SQL to find all of the rows where both A is connected to B and vice versa. The query would return (no duplications allowed):

connectionA    ConnectionB
   887             225
   887             562


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜