Disabled Feature Flags
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
- Vesta Innovations
Problem
The platform team is auditing stale feature flags that may be safe to remove. Pull all flags that are currently disabled, showing every column.
Disabled flags. Still worth auditing.
Tables
feat_flags
Columns: flag_id INTEGER, flag_name TEXT, enabled INTEGER, rollout REAL, owner TEXT, created TEXT, updated TEXT
| flag_id | flag_name | enabled | rollout | owner | created | updated |
|---|---|---|---|---|---|---|
| 131 | new_checkout | 0 | NULL | engineering | 2025-02-02 | 2026-02-02 |
| 162 | beta_search | 0 | NULL | growth | 2025-03-03 | 2026-03-03 |
| 193 | ai_recs | 1 | 39 | platform | 2025-04-04 | 2026-04-04 |
| 224 | live_chat | 0 | NULL | mobile | 2025-05-05 | 2026-05-05 |
| 255 | video_upload | 0 | NULL | data | 2025-06-06 | 2026-06-06 |
| 286 | two_factor | 1 | 78 | product | 2025-07-07 | 2026-07-07 |
| 317 | bulk_export | 0 | NULL | engineering | 2025-08-08 | 2026-08-08 |
| 348 | new_dashboard | 0 | NULL | growth | 2025-09-09 | 2026-09-09 |
| 379 | mobile_v2 | 1 | 17 | platform | 2025-10-10 | 2026-01-10 |
| 410 | dark_mode | 0 | NULL | mobile | 2025-11-11 | 2026-02-11 |
Expected output
| flag_id | flag_name | enabled | rollout | owner | created | updated |
|---|---|---|---|---|---|---|
| 131 | new_checkout | 0 | NULL | engineering | 2025-02-02 | 2026-02-02 |
| 162 | beta_search | 0 | NULL | growth | 2025-03-03 | 2026-03-03 |
| 224 | live_chat | 0 | NULL | mobile | 2025-05-05 | 2026-05-05 |
| 255 | video_upload | 0 | NULL | data | 2025-06-06 | 2026-06-06 |
| 317 | bulk_export | 0 | NULL | engineering | 2025-08-08 | 2026-08-08 |
Worked solution and explanation
What this really is
Strip the audit story away and this is one predicate: keep the rows whose stored state is off. The whole question is where 'off' lives. In feat_flags it lives in enabled, an integer that is 0 or 1. Candidates who skim the sample rows often notice the blank rollout cells first and filter on those, or type enabled = 'false' as if the column were text. The first happens to line up on this data and breaks the day someone switches off a flag without clearing its rollout percentage. The second compares an integer to a word, matches nothing, and hands the auditor an empty list.
Step 1: Find where the off state is stored
Read the column types before reading the rows. enabled is an INTEGER holding 0 or 1, so 'off' is the value 0. rollout is a percentage that only gets filled in for live flags. It is a side effect of the state, not the state itself.
Step 2: Keep only the off rows
enabled = false and enabled = 0 are the same test here, because the engine treats false as 0. What matters is comparing against the number. Of the 200 flags, 134 survive; the 66 live ones never reach the reviewer.
Step 3: Return the whole row
The auditor wants every column, so the projection is *. A hand-picked column list is exactly the kind of thing that silently drops owner or updated, and the reviewer needs both to decide who to ask before deleting a flag.
SELECT *
FROM feat_flags
WHERE enabled = falseOne pass over feat_flags, keeping the rows where enabled is 0.
Common follow-up questions
- What changes between `enabled = false` and `NOT enabled` if `enabled` could be `NULL`? (Three-valued logic: a `NULL` state is neither on nor off, so both forms drop it, and only an explicit `IS NULL` check surfaces it.)
- How would you also show how long each flag has been off? (Treat `updated` as the last change and compute the days between it and `CURRENT_DATE`.)
- What if the audit only wanted flags switched off more than 90 days ago? (Add a date bound on `updated`, the closest record this table has of when the state last changed.)