Gaya3
Gaya3

Reputation: 3

To combine the data from different tables in sql

I have a column which is present in 4 different tables. The data of this column will differ from each table. It may contain some duplicates as well. Now I want to extract the unique data for this column from all 4 tables.

Note: I don't want to compare the values of other columns in any of the tables. Just the distinct data for this column is needed.

Eg:

Table 1: a, b, c
table 2: a, d, e
table 3: a, f, g
table 4: a, h, i

result :

a
-----------
1
2
3
4

Upvotes: 0

Views: 45

Answers (1)

Mayank Jain
Mayank Jain

Reputation: 2564

You can use union. Assuming you don't need efficient query. Try below:

select a from t1 union
select a from t2 union
select a from t3 union
select a from t4

Upvotes: 1

Related Questions