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

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*
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


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

select *, 1 as on_table_one, 0 as on_table_two from table_1
select *, 0, 1 from table_2

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x