Fairfield
asked on
SQL recursive insert
I have two tables.
Table1 looks like this:
PartNumber
123456-001
122334-002
22334455-003
Table2 looks like this:
Country
AA
BB
CC
DD
EE
I need a query that will take each line of Table1 and insert into new table (Table3) by taking each line from Table1 and use the sequence from Table2.
Table3 should look like this:
PartNumber Country
123456-001 AA
123456-001 BB
123456-001 CC
123456-001 DD
123456-001 EE
122334-002 AA
122334-002 BB
122334-002 CC
122334-002 DD
122334-002 EE
.....etc.
Can someone please provide a query that will provide the resulting table?
Table1 looks like this:
PartNumber
123456-001
122334-002
22334455-003
Table2 looks like this:
Country
AA
BB
CC
DD
EE
I need a query that will take each line of Table1 and insert into new table (Table3) by taking each line from Table1 and use the sequence from Table2.
Table3 should look like this:
PartNumber Country
123456-001 AA
123456-001 BB
123456-001 CC
123456-001 DD
123456-001 EE
122334-002 AA
122334-002 BB
122334-002 CC
122334-002 DD
122334-002 EE
.....etc.
Can someone please provide a query that will provide the resulting table?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
FYI:
The CARTESIAN JOIN or CROSS JOIN returns the Cartesian product of the sets of records from two or more joined tables. Thus, it equates to an inner join where the join-condition always evaluates to either True or where the join-condition is absent from the statement.https://www.tutorialspoint.com/sql/sql-cartesian-joins.htm
insert into table3 (select partnumber, country from table1, table2);