Home > Net >  Add True or False if data came from specific table after combing
Add True or False if data came from specific table after combing

Time:10-05

If I have these two tables:

Table 1)

resto_name | city
Resto A    | Paris

Table 2)

resto_name | city
Resto B    | Doha

If I combine two tables like this:

select * from *Table 1*
union
select * from *Table 2*

resto_name | city
Resto A    | Paris
Resto B    | Doha

How will I be able to know that Resto A came from Table 1 and Resto B came from Table 2? I need to save the selected data to another Table.

This is the expected output on Table 3:

resto_name | city   | on_table_one | on_table_two
Resto A    | Paris  | True         | False
Resto B    | Doha   | False        | True

CodePudding user response:

select *, 1 as on_table_one, 0 as on_table_two from table_1
union
select *, 0, 1 from table_2
  • Related