EasySQL
Merge Customer Email Lists
SQLDatabases
Your company stores VIP customers and standard customers in separate tables.
Write a SQL query that returns all unique emails from both tables,
sorted alphabetically.
Tables
vip_customers: id, emailstandard_customers: id, email
| vip | |
|---|---|
| 1 | alice@example.com |
| 2 | bob@example.com |
| 3 | carol@example.com |
| standard | |
|---|---|
| 1 | dave@example.com |
| 2 | alice@example.com |
| 3 | eve@example.com |
Expected output (column: email) — alice appears once despite being in both tables.
alice@example.com
bob@example.com
carol@example.com
dave@example.com
eve@example.com
UNIONremoves duplicates. UseUNION ALLto keep them.
Sample tests
Test #1alice is in both — UNION deduplicates to 5 rows
Input: "CREATE TABLE vip_customers (id INTEGER, email TEXT);\nCREATE TABLE standard_customers (id INTEGER, email TEXT);\nINSERT INTO vip_customers VALUES\n (1, 'alice@example.com'), (2, 'bob@example.com'), (3, 'carol@example.com');\nINSERT INTO standard_customers VALUES\n (1, 'dave@example.com'), (2, 'alice@example.com'), (3, 'eve@example.com');"
Output: "alice@example.com\nbob@example.com\ncarol@example.com\ndave@example.com\neve@example.com"