I have 2 tables that I want to join, when I try it gives me error of "ambiguous" the thing is both tables after joining them should generate new rows since values will match more than 1 time.
table_1
| row_a | row_b | row_c |
|---|---|---|
| abc | True | 1992 |
| abc | False | 1992 |
table_2
| row_c | row_d | row_e |
|---|---|---|
| 1992 | old | expired |
| 1992 | new | recent |
I want to join them and create
| row_a | row_b | row_c | row_d | row_e |
|---|---|---|---|---|
| abc | True | 1992 | old | expired |
| abc | True | 1992 | new | recent |
| abc | False | 1992 | old | expired |
| abc | False | 1992 | new | recent |
It has to be in SQL create new table, no python or anything else like it. In reality the code needs to join based on 2 columns.
CodePudding user response:
CROSS JOIN gets you the wanted result
SELECT row_a,row_b,table_1.row_c,row_d, row_e FROM table_1 CROSS JOIN table_2;
