开发者

Combining common values in SQL

开发者 https://www.devze.com 2023-04-09 13:41 出处:网络
Say for Instance I have the following table (full of connections between members) connectionAConnectionB

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

精彩评论

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