How to combine result sets using UNION and UNION ALL in MySQL?
Combines row results from multiple SELECT queries with or without duplicate elimination.
-- UNION: Combines datasets and removes duplicate entries SELECT first_name, 'Employee' AS role FROM employees UNION SELECT dept_name, 'Department' AS role FROM departments; -- UNION ALL: Retains all rows including duplicates SELECT first_name FROM employees UNION ALL SELECT last_name FROM employees;
+------------+------------+ | first_name | role | +------------+------------+ | John | Employee | | Alice | Employee | | Carol | Employee | | Engineering| Department | | Marketing | Department | +------------+------------+