I have three tables that have four columns in common. I want a query that retrieves data from these four columns. For example, the four columns are id, name, email, phone. I want to retrieve data from those four columns.
Can someone help?
Use UNION:
select id, name, email, phone
from table1
union
select id, name, email, phone
from table2
union
select id, name, email, phone
from table3;
In the above query identical rows from different tables will be presented as one row. If you want all rows from all tables use UNION ALL.
Use INTERSECT to select only identical rows in all three tables:
select id, name, email, phone
from table1
intersect
select id, name, email, phone
from table2
intersect
select id, name, email, phone
from table3;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With