This is a discussion on eliminating (inverse) duplicates in result within the SQL Server forums, part of the Microsoft SQL Server category; --> Am I going about this the right way? I want to find pairs of entities in a table that ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Am I going about this the right way? I want to find pairs of entities in a table that have some relationship (such as a field being the same), so I select t1.id, t2.id from sametable t1 join sametable t2 on t1.id<>t2.id where t1.fieldx=t2.fieldx ... The trouble is, this returns each pair twice, e.g. B C C B M N N M Is there a way to do this kind of thing and only get each pair once? Kerry |
| |||
| Try this: SELECT t1.id, t2.id FROM sametable t1 JOIN sametable t2 ON t1.id < t2.id WHERE t1.fieldx=t2.fieldx ... (a subtle difference in the ON clause) -- David Portas ------------ Please reply only to the newsgroup -- |
| Thread Tools | |
| Display Modes | |
|
|