Overview
Build one mailing list from customers and newsletter subscribers with UNION, and know when duplicates are removed or kept.
- UNION stacks results
- UNION removes duplicates, UNION ALL keeps them
- ORDER BY at the very end
Short Course
UNION stacks the rows of two queries that have the same columns. Trap:
UNION removes duplicate rows but UNION ALL keeps them. Choose on purpose:
one email per person, or every row for counting.
SELECT city FROM customers
UNION ALL -- keeps repeats, e.g. to count
SELECT city FROM suppliers;
Task
Return one mailing list with every email from customers and from
subscribers, each address once, in alphabetical order. In the database
below, [email protected] is in both tables.
Database
Sample data from the first test. The other tests use different rows, so write a query, not a list of answers.
| idINTEGER | emailTEXT |
|---|---|
| 1 | [email protected] |
| 2 | [email protected] |
| idINTEGER | emailTEXT |
|---|---|
| 1 | [email protected] |
| 2 | [email protected] |
Test Suites
Pending
Next
Output