Timeout Warning Logs

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

During an incident postmortem, the on-call engineer needs all available fields for warning-level log entries where the message mentions a timeout.

Timeout warnings. The postmortem trail.

Tables

server_logs

Columns: log_id INTEGER, server_name TEXT, log_level TEXT, message TEXT, response_time_ms INTEGER, log_timestamp TEXT

server_logs: 10 of 200 rows
log_idserver_namelog_levelmessageresponse_time_mslog_timestamp
137web-prod-02WARNConnection timeout after 30s232026-02-02 01:07:13
174api-prod-01ERRORDatabase query slow: 2.5sNULL2026-03-03 02:14:26
211api-prod-02DEBUGCache miss for key user_123492026-04-04 03:21:39
248db-primaryCRITICALMemory usage at 85%02026-05-05 04:28:52
285db-replica-01INFOSSL certificate expires in 7 daysNULL2026-06-06 05:35:05
322cache-01WARNRate limit exceeded for IP 192.168.1.x882026-07-07 06:42:18
359worker-01ERRORDisk space low: 10% remaining1012026-08-08 07:49:31
396cdn-edge-usDEBUGNew deployment v2.3.1 startedNULL2026-09-09 08:56:44
433cdn-edge-euCRITICALHealth check passed1272026-01-10 09:03:57
470monitor-01INFOFailed to connect to upstream1402026-02-11 10:10:10

Expected output

First 4 of 4 rows
log_idserver_namelog_levelmessageresponse_time_mslog_timestamp
137web-prod-02WARNConnection timeout after 30s232026-02-02 01:07:13
3652cdn-edge-usWARNConnection timeout after 30s12582026-07-13 00:12:48
10003801web-prod-02WARNConnection timeout after 30s232022-01-02 01:07:13
10003896cdn-edge-usWARNConnection timeout after 30s12582022-12-13 00:12:48

Worked solution and explanation

What this really is

This is a two-predicate filter dressed up as an incident postmortem. Anyone gets the log_level = 'WARN' half right. What separates candidates is reading 'mentions a timeout' as a substring test, message LIKE '%timeout%', and keeping both halves joined by AND. Write message = 'timeout' and you get zero rows, because every message is a full sentence like 'Connection timeout after 30s'. Drop either half and you get one of two failures: every warning in the table, or timeout lines logged at INFO and ERROR buried among the real warnings. During a live incident, an empty result reads as 'no timeouts happened'.


Break down the requirements

Step 1: Confirm the literal

Ask whether message must contain the substring timeout or also variants like timed out. The brief says 'mentions a timeout', so a LIKE '%timeout%' substring match on message is the agreed interpretation.

Step 2: Pin the severity literal

Confirm that log_level is stored as 'WARN' (not 'WARNING' or 'warn'). String equality in WHERE is case sensitive in most engines, and one wrong literal returns zero rows after a 50M-row scan.

Step 3: Select all fields

The postmortem needs every column, so SELECT * is correct here. Do not project a subset: on-call wants response_time_ms, server_name and log_timestamp alongside message.

Step 4: Combine with AND

Join the two predicates on log_level and message with AND. You need no IN list or OR chain, because there is one severity and one substring.


The solution

TIMEOUT WARNING LOGS
SELECT *
FROM server_logs
WHERE log_level = 'WARN'
  AND message LIKE '%timeout%'

Common follow-up questions

Common follow-up questions