SQL interview question: Skip Duplicates With INSERT OR IGNORE
Idempotent Customer Import
A CSV import can contain customers you already have. The import must never crash on duplicates - existing rows win.
Write a single INSERT OR IGNORE statement adding these two customers:
- customer_id 105, name 'Duplicate Dan', email '[email protected]', city 'Boston', signup_date '2024-06-01' (already exists - must be skipped)
- customer_id 113, name 'Nadia Flores', email '[email protected]', city 'Austin', signup_date '2024-06-01' (new)
Note: Your change is verified automatically and rolled back afterwards.
This challenge changes data. Your statement runs on a private copy of the database, then we check the resulting table.
Tables
customers 12 rows
- customer_id integer PK
- name text
- email text
- city text
- signup_date text
| customer_id | name | city | signup_date | |
|---|---|---|---|---|
| 101 | Alice Mitchell | [email protected] | San Francisco | 2024-01-15 |
| 102 | Bob Chen | [email protected] | New York | 2024-02-20 |
| 103 | Carol Davis | [email protected] | Los Angeles | 2024-03-10 |