Find Deploy Authors
An easy SQL interview practice problem on DataDriven. Write the query and run it against a real database, with instant feedback.
- Domain
- SQL
- Difficulty
- easy
- Seniority
- L3
- Asked in
Problem
Which spellings of alice and bob appear in deploy_logs, counting every capitalization of either name? We're cleaning up the author field and need each variant the logs carry, exactly as written.
Same person. Many different spellings.
Tables
deploy_logs
Columns: log_id INTEGER, svc_name TEXT, version TEXT, env_name TEXT, status TEXT, deploy_at TEXT, dur_secs INTEGER, author TEXT
| log_id | svc_name | version | env_name | status | deploy_at | dur_secs | author |
|---|---|---|---|---|---|---|---|
| 131 | payment-api | v1.0.2 | staging | failed | 2026-02-02 01:11:00 | 23 | bob |
| 162 | user-svc | v1.1.0 | dev | rolled_back | 2026-03-03 02:22:00 | 36 | charlie |
| 193 | search-api | 2.0.0 | canary | in_progress | 2026-04-04 03:33:00 | 49 | dana |
| 224 | gateway | v2.1.0 | Production | Success | 2026-05-05 04:44:00 | 62 | eve |
| 255 | notif-svc | 2.1.1 | STAGING | FAILED | 2026-06-06 05:55:00 | 75 | frank |
| 286 | analytics | v3.0.0-rc1 | production | success | 2026-07-07 06:06:00 | 88 | Alice |
| 317 | ml-serving | v1.0.3 | staging | failed | 2026-08-08 07:17:00 | NULL | BOB |
| 348 | auth-svc | v1.0.1 | dev | Rolled_Back | 2026-09-09 08:28:00 | 114 | alice |
| 379 | Payment-API | v1.0.2 | canary | in_progress | 2026-01-10 09:39:00 | 127 | bob |
| 410 | user-svc | v1.1.0 | Production | Success | 2026-02-11 10:50:00 | 140 | charlie |
Expected output
| author |
|---|
| bob |
| Alice |
| BOB |
| alice |
Worked solution and explanation
What this is really asking
This is a data-quality audit wearing a lookup costume. Anyone can filter a name. The skill is folding case in exactly one place: inside the comparison, never in what you return. Match with = and you only find 'alice' and 'bob'. Fold the output too and 'Alice' merges into 'alice', which hides the exact inconsistency the cleanup exists to surface.
Break down the requirements
Step 1: Match case-insensitively
WHERE LOWER(author) IN ('alice', 'bob') catches 'Alice', 'BOB' and any other casing. Keep the literals lowercase so they meet the folded column on equal terms.
Step 2: Return the raw spelling
Select author itself, not LOWER(author). The cleanup wants to see 'Alice' and 'alice' as separate rows, because that difference is the problem being fixed.
Step 3: Collapse repeat deploys
deploy_logs holds 500,000 rows and each person ships many deploys, so DISTINCT turns hundreds of matching rows into one row per spelling.
The solution
SELECT DISTINCT author
FROM deploy_logs
WHERE LOWER(author) IN ('alice', 'bob')- Folded output
SELECT DISTINCT LOWER(author)returns 'alice' and 'bob': two tidy rows that tell the cleanup nothing is wrong.- Folded predicate only
SELECT DISTINCT author ... WHERE LOWER(author) IN (...)returns every stored casing, which is the list the cleanup actually has to fix.
Common follow-up questions
- How would you make this lookup index-friendly on a hot path? (An expression index on `LOWER(author)` lets the planner seek instead of scan.)
- How would you report how many deploys each spelling accounts for? (Add `COUNT(*)` and `GROUP BY author`; the `LOWER()` filter stays in the `WHERE`.)
- What if you needed every author whose name starts with 'al'? (`LOWER(author) LIKE 'al%'` can still use an expression index because the wildcard trails.)