Unique Searchers

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
Airbnb

Problem

The search team is measuring platform penetration: how many unique users have performed at least one search?

How many users actually searched?

Tables

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 1 of 1 rows
unique_searchers
75

Worked solution and explanation

Why this problem exists in real interviews

This is a basic COUNT(DISTINCT ...) problem. Interviewers use it to verify that you understand the difference between counting rows and counting unique entities.


Break down the requirements

Step 1: Count unique users

COUNT(DISTINCT user_id) returns the number of unique users who have performed at least one search.


The solution

Single distinct count
SELECT COUNT(DISTINCT user_id) AS unique_searchers
FROM search_queries

Common follow-up questions