views:

43

answers:

2

I've got a simple problem that really has me stumped.

I have a master table Table X

Table X
ID
_________
1
2
3
4
5

I have a join table for Table X that allows records to be self joined. Let's call this JoinTableX

JoinTableX
RecordAID RecordBID
--------- --------
1         2        (So Record 1 from Table X has a link to Record 2 from Table X)
1         3
1         4
2         3
2         4
3         1
3         2
4         1
4         2

So how do I write a SQL query to show me all the records in JoinTableX that have a duplicate dependency on each other (example bove Table X Record 1 is linked to Table X Record 4 and Table X Record 4 is linked to Table X Record 1.

+4  A: 
select *
from JoinTableX a
inner join JoinTableX b on a.RecordAID = b.RecordBID 
    and a.RecordBID = b.RecordAID
RedFilter
+1  A: 
(SELECT RecordAID, RecordBID FROM JoinTableX)
INTERSECT
(SELECT RecordBID, RecordAID FROM JoinTableX)
ElectricDialect