Search RU
Tasks / SQL / Finding duplicate orders
Statement easy

Finding duplicate orders

`find_duplicate_orders(conn)` returns orders that have at least one other
order with the same `customer_id`, `amount`, and `order_date`.

Table schema:

```sql
CREATE TABLE orders (
id INTEGER PRIMARY KEY,
customer_id INTEGER,
amount REAL,
order_date TEXT
)
```

Contract:

- a duplicate is a match on all three fields: `customer_id`, `amount`,
`order_date`;
- return **every** order in a duplicate group, not one row per group;
- `NULL` is an ordinary value: two rows with `NULL` in one field and the same
remaining fields are duplicates;
- the result is sorted by `id` ascending;
- each item is a dict with the keys `id`, `customer_id`, `amount`,
`order_date`;
- an empty table returns an empty list.

**Example:**

```
id=1, customer_id=10, amount=100.0, order_date="2024-01-01"
id=2, customer_id=10, amount=100.0, order_date="2024-01-01"
id=3, customer_id=11, amount=100.0, order_date="2024-01-01"

→ [{"id": 1, ...}, {"id": 2, ...}]
```

Write tests on `sqlite3.connect(":memory:")`: ordinary duplicates, no
duplicates, `NULL`, and boundaries.

Python · SQLite
sqlsqliteduplicatesnull
test_solution.py Python 3.14 · SQLite
AI mentor

The AI mentor is available after you log in: it sees your attempt history and does not spend resources on anonymous requests.

Log in and ask
Hints 1 of 3 unlocked · attempts: 0
Hint 1

What makes two orders duplicates: a match on all three fields, or only two? And is `NULL` a value that can equal another `NULL`?

Hint 2 — unlocks after 1 attempt
Hint 3 — unlocks after 3 attempts