Union SQL Tutorial

Union Syntax:

SELECT column_name(s) FROM table_name_a
UNION
SELECT column_name(s) FROM table_name_b

Union All Syntax:

SELECT column_name(s) FROM table_name_a
UNION ALL
SELECT column_name(s) FROM table_name_b

Employee_aEmployee_b
idname
1Martin
2Carol
3Davis
4Sandra
idname
1David
2Barbara
3Carol
4Sandra

UNION Example:

SELECT * FROM employee_a UNION SELECT * FROM employee_b;

UNION Result:

1Martin
2Carol
3Davis
4Sandra
1David
2Barbara
3Carol

UNION ALL Example:

SELECT * FROM employee_a UNION ALL SELECT * FROM employee_b;

UNION ALL Result:

1Martin
2Carol
3Davis
4Sandra
1David
2Barbara
3Carol
4Sandra