The Words That Page Us

A hard SQL interview practice problem on DataDriven. Write the query and run it against a real database, with instant feedback.

Domain
SQL
Difficulty
hard
Seniority
L4
Asked in
Yelp

Problem

During an incident review, on-call wants every chat message mentioning 'latency', 'down', 'back', or 'pipeline' lined up against the error tracking entries logged in the same month. Show the channel, the message text, and the severity of the error it matched.

Certain words trigger an investigation.

Tables

chat_msgs

Columns: msg_id INTEGER, channel TEXT, sender_id INTEGER, content TEXT, msg_type TEXT, sent_at TEXT, edited INTEGER, reply_to INTEGER

chat_msgs: 10 of 200 rows
msg_idchannelsender_idcontentmsg_typesent_ateditedreply_to
147#engineering197Anyone seeing increased latency?file2026-02-02 01:07:000NULL
194#incidents294PR #412 ready for reviewreaction2026-03-03 02:14:000NULL
241#random391Dashboard is downthread_reply2026-04-04 03:21:000NULL
288#deployments488Fixed the flaky testsystem2026-05-05 04:28:000NULL
335#data-team585Merged the migrationText2026-06-06 05:35:000NULL
382#general682NULLFILE2026-07-07 06:42:000NULL
429#engineering779LGTMtext2026-08-08 07:49:000NULL
476#incidents876👍file2026-09-09 08:56:0005
523#random973reaction2026-01-10 09:03:000NULL
570#deployments1070Can someone check the pipeline?thread_reply2026-02-11 10:10:000NULL

err_tracks

Columns: err_id INTEGER, err_type TEXT, message TEXT, svc_name TEXT, severity TEXT, count INTEGER, first_at TEXT

err_tracks: 10 of 200 rows
err_iderr_typemessagesvc_nameseveritycountfirst_at
137TypeErrorCannot read property of undefinedpayment-apierror82026-02-02 01:11:00
174ConnectionTimeoutConnection timed out after 30suser-svcwarning152026-03-03 02:22:00
211OutOfMemoryHeap space exhaustedsearch-apiinfo222026-04-04 03:33:00
248FileNotFoundFile /tmp/data.csv not foundgatewayFatal292026-05-05 04:44:00
285PermissionDeniedAccess denied for user rootworkerERROR362026-06-06 05:55:00
322RateLimitExceededToo many requests from 10.0.0.1auth-svcfatal432026-07-07 06:06:00
359ParseErrorMalformed JSON in request bodypayment-apierror502026-08-08 07:17:00
396nullpointerexceptionStack overflow in recursive calluser-svcwarning572026-09-09 08:28:00
433TYPEERRORDivision by zerosearch-apiinfo642026-01-10 09:39:00
470NullPointerExceptionUnexpected null value at line 42gatewayFatalNULL2026-02-11 10:50:00

Expected output

First 5 of 934 rows
channelcontentseverity
#engineeringAnyone seeing increased latency?error
#engineeringAnyone seeing increased latency?Fatal
#randomDashboard is downinfo
#deploymentsCan someone check the pipeline?error
#data-teamRolling back to v2.0warning

Worked solution and explanation

Why this problem exists in real interviews

Strip the incident-review costume and this is a derived-string equi-join hiding a many-to-many explosion. The only thing tying a chat message to an error is the calendar month you carve out of two timestamp strings, so SUBSTR(sent_at, 1, 7) isn't formatting, it IS the join key. Anyone can write the OR-chain keyword filter; what separates candidates is naming, out loud, that equal months pair every matching message with every same-month error before they hit run. Miss it and the result balloons past 100M rows per month bucket while partition pruning quietly dies, because the planner cannot push a SUBSTR expression down to the partition column.


Break down the requirements

Step 1: Filter messages by keyword

OR-chain of cm.content LIKE on '%latency%', '%down%', '%back%', '%pipeline%'. Leading wildcards mean no btree index helps. Wrap in LOWER() if the engine is case-sensitive.

Step 2: Define same-month

SUBSTR(cm.sent_at, 1, 7) = SUBSTR(et.first_at, 1, 7) gives 'YYYY-MM'. Works on ISO strings or timestamps cast to text. Both sides are derived, so neither partition key gets pruned.

Step 3: Project the three columns

cm.channel, cm.content, et.severity. No aggregation in the spec, so duplicates from the many-to-many join land in the result set.

Step 4: Decide on shape

One chat row pairs with every same-month error. Confirm with the interviewer: per-message-per-error, or DISTINCT on (channel, content, severity), or one row per message with max severity.


The solution

INCIDENT KEYWORD MATCH
SELECT cm.channel, cm.content, et.severity
FROM chat_msgs cm
INNER JOIN err_tracks et
  ON SUBSTR(cm.sent_at, 1, 7) = SUBSTR(et.first_at, 1, 7)
WHERE cm.content LIKE '%latency%'
   OR cm.content LIKE '%down%'
   OR cm.content LIKE '%back%'
   OR cm.content LIKE '%pipeline%'

COMMON FOLLOW-UP QUESTIONS

Common follow-up questions