Hello SQL expert,
I am trying to combine these two tables, TBL1 and TBL2 into one table called "Expecting TBL"
Here is the Create and Insert SQL statement for TBL1 and TBL2.
CREATE TABLE TBL1
(
ID CHAR(4),
CODE VARCHAR(10),
UNIT INT
)
INSERT INTO TBL1 (ID, CODE, UNIT)
VALUES ('APM1','12','1500'),('APM1','33','4500'),('APM1','33','200'),('APM1','525','150'),('APM1','525','100'),('APM1','667','175')
,('APM2','33','12500'),('APM2','563','5500'),('APM2','711','1500')
,('APM3','223','5000'),('APM3','223','4500'),('APM3','4','250')
CREATE TABLE TBL2
(
ID CHAR(4),
NAME VARCHAR(10),
COLOR VARCHAR(10)
)
INSERT INTO TBL2 (ID, NAME, COLOR)
VALUES ('APM1','John','Black'),('APM1','John','Red'),('APM1','John','Blue'),('APM1','John','Yellow'),('APM1','John','Green'),('APM1','John','Black'),('APM1','John','White'),('APM1','John','Brown'),('APM1','John','Red'),('APM1','John','Blue')
,('APM2','Mel','12500'),('APM2','Mel','Red'),('APM2','Mel','White')
,('APM3','Todd','Green'),('APM3','Todd','Black')
And here are the TBL1 and TBL2 output:
and here is the output I want to see in one table:
Anyone knows how can I achieve this in SQL? FYI, the number of records in TBL1 could be more so that will expand the columns in the combining table to the right handside.
Thank you