Introduction
Set operations combine results from two or more queries into one list. ORDER BY sorts the combined list to make it easier to read or find data.
Jump into concepts and practice - no test required
SELECT column_list FROM table1 UNION | UNION ALL | INTERSECT | EXCEPT SELECT column_list FROM table2 ORDER BY column_name [ASC|DESC];
SELECT name FROM customers_north UNION SELECT name FROM customers_south ORDER BY name ASC;
SELECT product FROM store_a UNION ALL SELECT product FROM store_b ORDER BY product DESC;
SELECT employee FROM dept1 INTERSECT SELECT employee FROM dept2 ORDER BY employee;
CREATE TABLE fruits1 (name VARCHAR(20)); CREATE TABLE fruits2 (name VARCHAR(20)); INSERT INTO fruits1 VALUES ('Apple'), ('Banana'), ('Cherry'); INSERT INTO fruits2 VALUES ('Banana'), ('Date'), ('Apple'); SELECT name FROM fruits1 UNION SELECT name FROM fruits2 ORDER BY name ASC;
UNION operation do when combining results from two SELECT queries?name?table1 with values (1, 'Alice'), (2, 'Bob')table2 with values (2, 'Bob'), (3, 'Charlie')SELECT id, name FROM table1 UNION SELECT id, name FROM table2 ORDER BY id;
SELECT name FROM table1 UNION ALL ORDER BY name SELECT name FROM table2;
employees with columns (id, name, department)contractors with columns (id, name, department)