Summary - UNION and INTERSECT
- SQL course
- Intermediate
- Lesson 64/115
- 5 min
Find rows in either or only one list with UNION and EXCEPT.
Summary - UNION and INTERSECT
UNION combines, INTERSECT intersects, EXCEPT takes the difference. All require the same column count.
SELECT name FROM customers
UNION
SELECT name FROM suppliers;Summary set operation.
name is selected from customers.
Practice Summary - UNION and INTERSECT
Summary: combine customer and supplier names with UNION.
Starter code
-- summary union
SELECT name FROM customersSample solution
SELECT name FROM customers
UNION
SELECT name FROM suppliers;Expected output
name Ayşe Mehmet ACME
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which keeps duplicates?
- UNION
- EXCEPT
- UNION ALL Correct answer
- INTERSECT
Explanation: UNION ALL keeps duplicates.
2 Summary - UNION and INTERSECT: match the terms
| Term | Meaning |
|---|---|
UNION |
union |
INTERSECT |
intersection |
EXCEPT |
difference |
UNION ALL |
with duplicates |