0

I need to INSERT INTO a new table (FinalTable) from 2 unrelated tables, but values from Table1 will need to be repeat for every value pulled from Table2.

Example:

Table1                      Table2                      
AK                          ID1
AL                          ID2
AR                          ID3
AZ                          ID4
...                         ...

FinalTable
Column1       Column2
ID1           AK
ID1           AL
ID1           AR
ID1           AZ
ID2           AK
ID2           AL
ID2           AR
ID2           AZ
...

Is it possible to do this without being able to JOIN the two SELECTed tables?

1 Answer 1

2

This is called a cross join.

INSERT dbo.FinalTable(Column1, Column2)
SELECT t1.col, t2.col 
  FROM dbo.Table1 AS t1
  CROSS JOIN dbo.Table2 AS t2;
1
  • Thank you Aaron, that took care of it!
    – eXult
    May 7, 2019 at 18:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.