I have table called : Tab1 , having column col1
Col1
A
B
C
D
Need a generic query to fetch below result
AB
AC
AD
BC
BD
CD
I have table called : Tab1 , having column col1
Col1
A
B
C
D
Need a generic query to fetch below result
AB
AC
AD
BC
BD
CD
declare @Tab1 table (col1 char(1)) insert into @Tab1 (col1) values ('A'),('B'),('C'),('D') select Tab1_1.col1 + Tab1_2.col1 from @Tab1 Tab1_1 join @Tab1 Tab1_2 on Tab1_2.col1 > Tab1_1.col1 order by Tab1_1.col1 ---- AB AC AD BC BD CD (6 rows affected)
As a bit of a sidebar, this is a classic example of an "Exclusive Triangular Join".
18 People are following this question.