Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 distinct combinations

Author  Topic 

Coolness
Starting Member

4 Posts

Posted - 2009-10-07 : 15:46:07
Hi all,
Say I have a table with a field of the letters of the alphabet, which for purposes here I'll say are only A,B,C,D. So my table:
A
B
C
D

I can create all combinations by
SELECT A.letters, B.letters FROM tblAlphabet AS A INNER JOIN tblAlphabet AS B ON A.letters!=B.letters
So
A B
A C
A D
B A
B C
B D
C A
C B
C D
D A
D B
D C

But what if I want to say that AB==BA, and so return only these unique combinations:
A B
A C
A D
B C
B D
C D

Can that be done with a SELECT?

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-10-07 : 16:26:46
replace "A.letters!=B.letters" with "a.letters < b.letters"

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -