Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between union and join?

Tags:

sql

join

union

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

like image 782
angel ansari Avatar asked May 17 '10 08:05

angel ansari


2 Answers

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.

like image 177
Dominic Rodger Avatar answered Oct 14 '22 22:10

Dominic Rodger


Think of joins as horizontal and unions as vertical

like image 30
Chris Bednarski Avatar answered Oct 14 '22 21:10

Chris Bednarski