# Clicked Ad Impressions

> They saw the ad. They clicked.

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

Domain: SQL · Difficulty: easy · Seniority: L3

## Problem

The ad analytics team needs the raw data behind every clicked impression for a detailed review. Pull all fields from ad impression records where the user clicked.

## Worked solution and explanation

### Why this problem exists in real interviews

This is the simplest possible filter query. It screens for the baseline ability to write a WHERE clause and use SELECT * correctly.

---

### Break down the requirements

#### Step 1: Filter to clicked impressions

`WHERE clicked = 1` restricts to rows where the user clicked.

#### Step 2: Return all fields

`SELECT *` returns every column as requested.

---

### The solution

**Simple equality filter**

```sql
SELECT *
FROM ad_impressions
WHERE clicked = 1
```

> **Cost Analysis**
>
> Full scan of 250M rows with a single equality filter. If click-through rates are ~1%, the output is ~2.5M rows. A partial index `WHERE clicked = 1` would accelerate this significantly.

> **Common Pitfall**
>
> Using `SELECT *` in production is generally discouraged because it returns all columns and breaks if the schema changes. In an interview, it is acceptable when the prompt says "all fields."

---

## Common follow-up questions

- Why might SELECT * be problematic in production? _(Tests awareness of schema evolution, network bandwidth, and query plan stability.)_
- How would you index this table for fast clicked-only queries? _(Tests partial index knowledge: CREATE INDEX ON ad_impressions (impression_id) WHERE clicked = 1.)_
- What if clicked were a boolean column? _(Tests type-aware filtering: WHERE clicked = true vs WHERE clicked = 1.)_

## Related

- [All practice problems](https://datadriven.io/problems)
- [Mock interview mode](https://datadriven.io/interview/clicked_ad_impressions)
- [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.