Non-Bot Acknowledged Alerts
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
- TransUnion
Problem
During on-call incident review, pull all alerts that were not acknowledged by 'alice', including alerts that were never acknowledged at all. Show all fields, and walk the incident timeline from the earliest alert that fired through to the most recent.
Human-acknowledged alerts only.
Tables
alert_events
Columns: alert_id INTEGER, svc_name TEXT, severity TEXT, status TEXT, fired_at TIMESTAMP, ack_by TEXT, resolved TIMESTAMP
| alert_id | svc_name | severity | status | fired_at | ack_by | resolved |
|---|---|---|---|---|---|---|
| 129 | payment-api | high | acknowledged | 2026-02-02 01:07:00 | bob | 2026-02-02 03:11:00 |
| 158 | user-svc | medium | resolved | 2026-03-03 02:14:00 | charlie | 2026-03-03 04:22:00 |
| 187 | search-api | low | silenced | 2026-04-04 03:21:00 | dana | NULL |
| 216 | gateway | Critical | firing | 2026-05-05 04:28:00 | NULL | 2026-05-05 06:44:00 |
| 245 | notif-svc | HIGH | acknowledged | 2026-06-06 05:35:00 | alice | 2026-06-06 07:55:00 |
| 274 | db-primary | critical | resolved | 2026-07-07 06:42:00 | bob | NULL |
| 303 | cache-01 | high | silenced | 2026-08-08 07:49:00 | charlie | 2026-08-08 09:17:00 |
| 332 | auth-svc | medium | firing | 2026-09-09 08:56:00 | NULL | 2026-09-09 10:28:00 |
| 361 | payment-api | low | acknowledged | 2026-01-10 09:03:00 | eve | NULL |
| 390 | user-svc | Critical | resolved | 2026-02-11 10:10:00 | alice | 2026-02-11 12:50:00 |
Expected output
| alert_id | svc_name | severity | status | fired_at | ack_by | resolved |
|---|---|---|---|---|---|---|
| 10003001 | payment-api | high | acknowledged | 2022-01-02 01:07:00 | bob | 2022-01-02 03:11:00 |
| 10003061 | notif-svc | high | acknowledged | 2022-01-06 13:07:00 | bob | 2022-01-06 15:11:00 |
| 10003026 | user-svc | medium | resolved | 2022-02-03 02:02:00 | bob | 2022-02-03 04:46:00 |
| 10003051 | search-api | low | silenced | 2022-03-24 03:57:00 | bob | NULL |
| 10003016 | auth-svc | Critical | firing | 2022-04-17 16:52:00 | NULL | 2022-04-17 18:56:00 |
Worked solution and explanation
What this really tests
This looks like a one-line filter on alert_events, but it is three-valued logic wearing an on-call costume. A not-equal comparison against NULL is neither true nor false, and WHERE keeps only rows that come out true. Most candidates write WHERE ack_by != 'alice' and move on. That silently drops every alert nobody ever acknowledged, 50 of the 200 rows here, so the result comes back with 120 rows instead of 170. Those are the alerts an on-call review most needs to see, and the prompt asks for them by name.
Break down the requirements
Step 1: Apply the NOT-alice filter with NULL awareness
For a row whose ack_by is NULL, ack_by != 'alice' evaluates to NULL, and WHERE drops it. The OR ack_by IS NULL branch is true for exactly those rows, so they come back in while alice's rows stay out.
Step 2: Order by fired_at
ORDER BY fired_at is ascending by default, which walks the timeline from earliest to latest. fired_at is stored as text in 'YYYY-MM-DD HH:MM:SS' form, so string order is chronological order here, and the column has no nulls to place.
Step 3: Return all fields
SELECT * returns all 7 columns in table order: the full alert record the review asked for.
The solution
SELECT *
FROM alert_events
WHERE ack_by != 'alice'
ORDER BY fired_atEvery row with ack_by null evaluates to NULL in the filter and is dropped, so the result comes back short of 170 rows.
SELECT *
FROM alert_events
WHERE ack_by != 'alice' OR ack_by IS NULL
ORDER BY fired_atThe OR ack_by IS NULL branch is the whole answer: it readmits the alerts nobody acknowledged.
- Bare inequality
WHERE ack_by != 'alice'keeps 'bob', 'eve' and the rest. The auth-svc 'firing' alert withack_bynull evaluates toNULLand disappears without any error.- NULL-aware
WHERE ack_by != 'alice' OR ack_by IS NULLkeeps the same named acknowledgers plus every never-acknowledged alert, which brings the result to the full 170 rows.
Common follow-up questions
- What happens to your result if `severity` contains `NULL` for some rows? (Tests whether the candidate knows a column no predicate references passes through untouched, and what changes once a filter on it is added.)
- How would you confirm that duplicate `alert_id` rows are not inflating the result? (Tests data quality awareness: a `GROUP BY alert_id HAVING COUNT(*) > 1` check before trusting the row count.)
- With 12 million alerts and a filter that keeps most of them, how would you keep this query fast as the table grows? (Tests layout knowledge: partition pruning on `fired_at` once the review is scoped to a window, and why an index on `ack_by` does not help a filter that keeps most rows.)