I have three tables. The first two tables have similar data but they come from different sources and they do not have the same amount of columns. I am using the third table to gather data from the other two tables. I would like a column in the third table that has the name of the table that the data came from.
Example:
table_1 contains the following data in the following order.
(ID, data_1, data_2, data_3, data_4, data_5)
table_2 contains the following data in the following order.
(ID, data_3, data_1, data_5, data_2, data_4, data_6, data_7)
I gather the data I need from both tables, table_3 has the same amount of columns as table_1.
First from table_1
INSERT INTO table_3
SELECT * FROM table_1
Then from table_2
INSERT INTO table_3
SELECT ID, data_1, data_2, data_3, data_4, data_5
FROM table_2
This is working and I have no problem with it. I would like to create a column in table_3 however that holds the name of the table that the data was taken from. I am not sure how to go about this. I added another column to table_3 so it now has a col_6 and then thought I could update that column manually but it is not working. This is what I tried.
UPDATE table_3
SET col_6 = 'table_1'
WHERE table_3.col_1 = table_1.col_1
UPDATE table_3
SET col_6 = 'table_2'
WHERE table_3.col_1 = table_2.col_1
Any help with this would be great, thank you.
AFAIK, there’s no way to do this automatically
but you can do something like this:
I’m not sure wahat Column_1 in your update statements reprsesent though.