How do I get every permutation in two totally unrelated tables with t-sql

后端 未结 3 1690
轻奢々
轻奢々 2021-01-14 12:13

I have two tables that are indirectly related by another table

TableA - ID, SomeFieldA

TableB - ID, SomeFieldB

TableAB - IDA, IDB, SomeFiel

3条回答
  •  礼貌的吻别
    2021-01-14 12:57

    You can do this:

    select
        a.*, b.*
    from
        a, b
    

    This will do a cross join which will give you all possible combinations.

    From there, it's simple to use that within the context of an INSERT statement to populate your AB table.

提交回复
热议问题