# Who's Looking

> Every search is a question someone needed answered. Count the people asking.

Canonical URL: <https://datadriven.io/problems/unique_searchers_count>

Domain: SQL · Difficulty: easy · Seniority: L3

## Problem

The search quality team needs a unique user reach metric. How many unique users have issued at least one search query?

## Worked solution and explanation

### Why this problem exists in real interviews

This is a fundamental `COUNT(DISTINCT ...)` question. Interviewers use it as a baseline check for aggregate function knowledge and understanding of unique vs. total counts.

---

### Break down the requirements

#### Step 1: Count distinct users

`COUNT(DISTINCT user_id)` returns the unique number of users who have issued at least one query from the 25M row `search_queries` table.

---

### The solution

**Distinct user count**

```sql
SELECT COUNT(DISTINCT user_id) AS unique_searchers
FROM search_queries
```

> **Cost Analysis**
>
> Scans 25M rows to build a hash set of 1.5M distinct user IDs. The hash set is the primary memory cost, but 1.5M integers is small.

> **Interviewers Watch For**
>
> Whether you alias the result column. Production queries should always have meaningful column names for downstream consumers.

> **Common Pitfall**
>
> Confusing `COUNT(DISTINCT user_id)` with `COUNT(user_id)`. The latter returns 25M (total rows with non-null user_id), not 1.5M unique users.

---

## Common follow-up questions

- How would you compute the average searches per user? _(Divide COUNT(*) by COUNT(DISTINCT user_id).)_
- What if you wanted the daily unique searcher count? _(Group by date-truncated query_time for a time-series metric.)_
- How does COUNT(DISTINCT) perform at scale with billions of rows? _(Tests knowledge of approximate count distinct (HyperLogLog) for large datasets.)_

## Related

- [All practice problems](https://datadriven.io/problems)
- [Mock interview mode](https://datadriven.io/interview/unique_searchers_count)
- [SQL Interview Questions](https://datadriven.io/sql-interview-questions)
- [Data Engineering Interview Prep Guide](https://datadriven.io/data-engineer-interview-prep)
- [Daily Challenge](https://datadriven.io/daily)

---

Source: DataDriven (https://datadriven.io). 100% free data engineering interview prep. Live code execution against Postgres 16, Python 3.11, and Spark sandboxes. No paywall, no premium tier, no signup gate.