tags:

views:

174

answers:

4

What is the difference between the SQL keywords union and join?

+13  A: 

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.

Dominic Rodger
Also, A union is from the branch of mathematics called set theory. This is a good image of a unionhttp://en.wikipedia.org/wiki/File:Venn0111.svg
Winter
+1 for including links
Andrew Heath
A: 

Union is a combination of elements from multiple sets.

Join is a subset of the cross product of multiple sets

Midhat
+4  A: 

Think of joins as horizontal and unions as vertical

Chris Bednarski
A: 

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
Andriy Mytroshyn