Silent Users

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

Domain
SQL
Difficulty
medium
Seniority
L4

Problem

An account counts as silent only when not a single row in search_queries belongs to it. From users, list every silent account's username and signup date, most recently joined first.

Users who have never typed a query.

Tables

users

Columns: user_id INTEGER, username TEXT, email TEXT, signup_date TEXT, account_status TEXT, age_bucket TEXT

users: 10 of 200 rows
user_idusernameemailsignup_dateaccount_statusage_bucket
100alicealice@example.com2025-02-02inactive25-34
197aaron42aaron42@example.com2026-03-03suspended35-44
294 ameliaamelia@example.com2024-04-04pending_verification45-54
391arjun arjun@example.com2025-05-05active55-64
488ava99ava99@example.com2026-06-06inactive65+
585andrew_kandrew_k@example.com2024-07-07suspendedNULL
682anikaanika@example.com2025-08-08 16:34:00pending_verification18-24
779aidenaiden@example.com2026-09-09 14:53:00active25-34
876aria_baria_b@example.com2024-10-10inactive35-44
973brianbrian@example.com2025-11-11suspended45-54

search_queries

Columns: query_id INTEGER, user_id INTEGER, search_term TEXT, results_count INTEGER, clicked_result INTEGER, query_time TEXT

search_queries: 10 of 200 rows
query_iduser_idsearch_termresults_countclicked_resultquery_time
2071100laptop deals1722026-02-02 01:11:00
2142197phone case iphone 153432026-03-03 02:22:00
2213294usb-c cable 6ft51NULL2026-04-04 03:33:00
2284NULLgaming mouse6852026-05-05 04:44:00
2355488mechanical keyboard8562026-06-06 05:55:00
24265854k monitor102NULL2026-07-07 06:06:00
2497682standing desk11982026-08-08 07:17:00
2568NULLwebcam 1080p13692026-09-09 08:28:00
2639876bluetooth speaker153NULL2026-01-10 09:39:00
2710973smart watch17012026-02-11 10:50:00

Expected output

First 5 of 125 rows
usernamesignup_date
viola_q2026-09-12
helena2026-09-12
aiden2026-09-09 14:53:00
francisco2026-09-05
leticia2026-09-01

Worked solution and explanation

This is a set difference dressed up as an engagement audit: every account in users minus every account that appears in search_queries. Anyone can say that out loud. What separates candidates is noticing that search_queries.user_id is blank on a quarter of the rows (50 of 200 here). Write the difference as user_id NOT IN (SELECT user_id FROM search_queries) and a single NULL in that list makes every comparison unknown. The audit then comes back empty and reports full engagement, when in fact 125 accounts have never searched.

Three moves to the answer

Step 1: Keep every account with a LEFT JOIN

Start from users and left-join search_queries on user_id. Every account survives the join. An account with no searches comes through once, with every search_queries column NULL. An inner join would discard exactly the rows the audit is looking for.

Step 2: Keep only the rows the join could not match

Filter with WHERE sq.query_id IS NULL. query_id is never NULL in the table, so a NULL there can only mean the account had no match. If you test a nullable column like clicked_result instead, you also sweep in active users whose searches never got a click.

Step 3: Sort newest signup first

ORDER BY u.signup_date DESC is the only ordering the audit asks for. Two accounts that signed up on the same day can come back in either order.

Silent accounts as a NULL-safe anti-join
SELECT u.username, u.signup_date
FROM users AS u
LEFT JOIN search_queries AS sq
  ON sq.user_id = u.user_id
WHERE sq.query_id IS NULL
ORDER BY u.signup_date DESC
The membership test
WHERE user_id NOT IN (SELECT user_id FROM search_queries) reads like the requirement word for word. But NOT IN means 'differs from every value in the list', and a comparison with NULL is never true. With 50 blank user_id values on file, it returns zero rows.
The unmatched-row filter
LEFT JOIN search_queries followed by WHERE sq.query_id IS NULL asks a different question: did this account match any search row at all? A blank user_id matches nobody, so it never affects the result, and all 125 silent accounts come back.

Common follow-up questions