Nobody Was Watching

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
Fidelity

Problem

Which services deployed with no corresponding alert record? Pull every deployment that has no matching alert for its service. Show the service name, version, environment, and deployment status, with the most recent deployment first.

Every release shipped clean. Not one had a tripwire set. Find the ones flying blind.

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

deploy_logs: 10 of 200 rows
log_idsvc_nameversionenv_namestatusdeploy_atdur_secsauthor
131payment-apiv1.0.2stagingfailed2026-02-02 01:11:0023bob
162user-svcv1.1.0devrolled_back2026-03-03 02:22:0036charlie
193search-api2.0.0canaryin_progress2026-04-04 03:33:0049dana
224gatewayv2.1.0ProductionSuccess2026-05-05 04:44:0062eve
255notif-svc2.1.1STAGINGFAILED2026-06-06 05:55:0075frank
286analyticsv3.0.0-rc1productionsuccess2026-07-07 06:06:0088Alice
317ml-servingv1.0.3stagingfailed2026-08-08 07:17:00NULLBOB
348auth-svcv1.0.1devRolled_Back2026-09-09 08:28:00114alice
379Payment-APIv1.0.2canaryin_progress2026-01-10 09:39:00127bob
410user-svcv1.1.0ProductionSuccess2026-02-11 10:50:00140charlie

alert_events

Columns: alert_id INTEGER, svc_name TEXT, severity TEXT, status TEXT, fired_at TEXT, ack_by TEXT, resolved TEXT

alert_events: 10 of 200 rows
alert_idsvc_nameseveritystatusfired_atack_byresolved
129payment-apihighacknowledged2026-02-02 01:07:00bob2026-02-02 03:11:00
158user-svcmediumresolved2026-03-03 02:14:00charlie2026-03-03 04:22:00
187search-apilowsilenced2026-04-04 03:21:00danaNULL
216gatewayCriticalfiring2026-05-05 04:28:00NULL2026-05-05 06:44:00
245notif-svcHIGHacknowledged2026-06-06 05:35:00alice2026-06-06 07:55:00
274db-primarycriticalresolved2026-07-07 06:42:00bobNULL
303cache-01highsilenced2026-08-08 07:49:00charlie2026-08-08 09:17:00
332auth-svcmediumfiring2026-09-09 08:56:00NULL2026-09-09 10:28:00
361payment-apilowacknowledged2026-01-10 09:03:00eveNULL
390user-svcCriticalresolved2026-02-11 10:10:00alice2026-02-11 12:50:00

Expected output

First 5 of 51 rows
svc_nameversionenv_namestatus
analyticsv3.0.0-rc1devrolled_back
payment-apiv1.0.2STAGINGFAILED
ml-servingv1.0.3STAGINGFAILED
payment-api v1.0.2canaryin_progress
Payment-APIv1.0.2canaryin_progress

Worked solution and explanation

What this problem really is

This is a set difference wearing an incident-review costume: which deployments belong to a service that never shows up in the alert table at all. Everyone reaches for a membership check, and that is exactly where it bites. Write NOT IN against a list of alert service names and the moment one alert row carries a NULL service, the whole result quietly collapses to zero rows. Flip to an INNER JOIN and you get the mirror image: deployments that DID alert. Only the LEFT JOIN with alert_id IS NULL survives, and you need both halves. Drop either one and you ship the wrong answer with a straight face.


Break down the requirements

Step 1: Left join on the service

LEFT JOIN deploy_logs to alert_events on svc_name alone. Match on the service, not the version or environment: one alert anywhere for a service knocks out all of its deployments. Unmatched deployments carry NULL alert columns.

Step 2: Filter for no match

WHERE ae.alert_id IS NULL keeps only the rows that found no partner. Filter on a NEVER-NULL alert column like the primary key; a nullable column would let real alerts leak through as false negatives.

Step 3: Sort by recency

ORDER BY deploy_at DESC puts the freshest deployments on top, which is what on-call scans first. Note repeats of the same service each stand as their own row; nothing here deduplicates.


The solution

Anti-join for unmatched records
SELECT dl.svc_name, dl.version, dl.env_name, dl.status
FROM deploy_logs dl
LEFT JOIN alert_events ae ON dl.svc_name = ae.svc_name
WHERE ae.alert_id IS NULL
ORDER BY dl.deploy_at DESC

Common follow-up questions