6

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?

1 Answer 1

11

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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.