Return all possible combinations of values on columns in SQL

后端 未结 8 2477
轮回少年
轮回少年 2020-11-28 10:44

How do I return a list of all combinations of values in 2 columns so they are new rows in T-SQL?

e.g.

Col1, Col2
----  ----
1     2
1     4
1     5
<         


        
8条回答
  •  野性不改
    2020-11-28 11:15

    I think this has been over complicated! Just:

    SELECT distinct Col1, Col2
    FROM MyTable
    

    to get all possible combinations..

提交回复
热议问题