+ 1
What are the differences between JOIN and UNION?
What are the differences between JOIN and UNION?
3 Answers
+ 2
Hey Sanjeev
JOIN is part of a single SELECT-statement and combines information from two tables in each row of the result-set. You need a common key in both tables to establish the connection in the ON part of the statement (eg customer-id in table customer and in table orders).
UNION combines two SELECT-statements, often from two different tables, to a result-set consisting of rows from both tables. Both SELECT-statemens need to select the same number of columns with equal data-types (eg columns name and email in table customers and table suppliers).
+ 2
UNION is used to unite two queries by adding more lines, if the columns are in the same order from the same table; or by adding more columns, otherwise.
JOINs filter the results of a query (not so different of a WHERE clause), specifically; while UNIONs match two queries together, and the filter goes on a JOIN or a WHERE clause.
0
Thanks maicon & stefan