codegurukool.com · Free coding tutorials & online compiler

Home › SQL Tutorial › SQL UNION and UNION ALL

SQL UNION and UNION ALL

Stack the results of two queries.

UNION joins the results of two SELECTs and removes duplicates. UNION ALL keeps duplicates. Both queries need the same number of columns with compatible types.

Example code

SELECT city FROM Customers WHERE country = 'UK'
UNION
SELECT city FROM Customers WHERE city = 'Paris'
ORDER BY city;

Run this code in the online editor

← SQL LEFT, RIGHT, FULL and SELF JOINSQL GROUP BY and HAVING →