Suppose I have a table 1 (4 rows and 3 columns) which is already in a database, I want to expand to table 2 using table 1 and variables (A, B, C, D). Table 2 will contain 8 rows and 5 columns. Can a simple select statement do that?
Table1
Col1 | Col2 | Col3 |
---|---|---|
R11 | R12 | R13 |
R21 | R22 | R23 |
R31 | R32 | R33 |
R41 | R42 | R43 |
Table 2
Col1 | Col2 | Col3 | Col4 | Col5 |
---|---|---|---|---|
R11 | R12 | R13 | A | B |
R21 | R22 | R23 | A | B |
R31 | R32 | R33 | A | B |
R41 | R42 | R43 | A | B |
R11 | R12 | R13 | C | D |
R21 | R22 | R23 | C | D |
R31 | R32 | R33 | C | D |
R41 | R42 | R43 | C | D |
2
Answers
You could use this DDL and SQL to create Table 2 from Table 1:
If you only want to expand Table 1 to look like your Table 2, you can use this DDL and SQL:
https://dbfiddle.uk/o13iC_Cr