+ 1

What are the differences between JOIN and UNION?

What are the differences between JOIN and UNION?

6th Apr 2018, 6:57 PM
Sanjeev Bomma
Sanjeev Bomma - avatar
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).
7th Apr 2018, 12:57 AM
Stefan
+ 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.
6th Apr 2018, 8:26 PM
Maicon Mauricio
Maicon Mauricio - avatar
0
Thanks maicon & stefan
7th Apr 2018, 3:41 AM
Sanjeev Bomma
Sanjeev Bomma - avatar