question

buddha avatar image
buddha asked

What is the sql?

Hi, I have A,B,C,D. I would like the combination of all the three letter only. What would be sql ?
sql-server-express
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
eghetto avatar image
eghetto answered
Excuse me sir, but there are **four** letters, not three... Anyway: You can use CROSS JOIN to create all combinations: DECLARE @myTable AS TABLE ( C CHAR NOT NULL ); INSERT INTO @myTable (C) VALUES ('A') ,('B') ,('C') ,('D'); SELECT mt2.C ,[@myTable].C FROM @myTable CROSS JOIN @myTable AS mt2;
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

KenJ avatar image KenJ commented ·
You might need a second cross join to get the 3rd letter in the combination :)
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.