I am querying names from two tables:
with data_1 as ( select names from tbl1), data_2 as ( select names from tbl2) select * from data_1 union select * from data_2
And I get the result I want in a single column.
Now I want to know if it is possbile to get the results in two different columns like: "names_from_data1", "names_from_data2"
Or another way to identify where each name comes from: data_1
or data_2
Advertisement
Answer
You can add hardcoded column to indicate the source:
with data_1 as ( select names, 'tbl1' as source from tbl1), data_2 as ( select names, 'tbl2' as source from tbl2) select * from data_1 union select * from data_2