JOINS and UNION Examples - SQL Query
What is the difference between JOINS and UNION.
A join is used to display columns with the same or different names from different tables. All columns are shown individually in the output.
The UNION operator is used to combine data from two tables with same data type. When UNION is performed, the data from both tables will be collected in a single column which has a same data type.
Consider the following tables.
Q. Write a query to perform UINON on column 'Customer_ID' from Table1 and Table2.
SELECT Supplier_ID FROM Supplier
SELECT Supplier_ID FROM Orders
ORDER BY Supplier_ID
This query will show the union of Supplier_ID column.
The union operator is used to avoid duplication of records. So the value 200 which is appear in the column Supplier_ID which is present in the both tables is displayed only once to avoid duplication.