Reputation: 89
What is the difference between the SQL keywords union
and join
?
Upvotes: 5
Views: 6596
Reputation: 689
Union:
UNION
you need to take care That col length, datatype and no.of columns used in SELECT
statement should be same in both tablesUNION
you should have at least two SELECT
statementsJoin:
JOIN
s there is no need to have rules mentioned in point 1.JOIN
used(Outer, Inner,Cartesian..)SELECT
statement is enoughHope this helps u..
Upvotes: 0
Reputation: 221
If need combinate more then one queries use operator Union, this operator execute first query and the second query, and then return all result in one dataset see more
select field from t1
union
select field from t2
If need create query to select data from two or more table then use operator join see more
select t1.field, t2.field
from t1.number inner join t2.key on t1.number=t2.key
Upvotes: 1
Reputation: 99761
The UNION
operator is used to combine the result-set of two or more SELECT
statements.
The JOIN
keyword is used in an SQL statement to query data from two or more tables, based on a relationship between certain columns in these tables.
The tutorials on these two topics (linked to above) on w3schools.com go into further detail.
Upvotes: 16
Reputation: 17810
Union is a combination of elements from multiple sets.
Join is a subset of the cross product of multiple sets
Upvotes: 1