Users with Ad Clicks
Which users have clicked on at least one ad?
- Sorting
- Distinct values
Challenge brief
Understand the request
Ads Operations needs a deduplicated list of all users who have engaged with at least one advertisement for retargeting purposes.
Return user_id in the declared deterministic order.
Return
- user_id
Constraints
- Return each user with an ad click once
- Order by user ID
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
ad_clicks
click_idINTEGERuser_idINTEGERad_idINTEGERclick_dateDATErevenueREAL
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
A user may have several click records.
Hint 2
Project the user key only once across the fact table.
Hint 3
Sort the deduplicated identifiers.
Verified SQL answer
Attempt the problem first, then compare structure and reasoning—not just syntax.
Reveal solution and explanation
SELECT DISTINCT user_id FROM ad_clicks ORDER BY user_idWhy this works
There are 30 ad click rows but only 20 distinct users. Some users clicked multiple ads (user 1 clicked 4 times, user 4 clicked twice). DISTINCT collapses multiple clicks by the same user into one row.
Success check
Returns the complete deterministic result for users with ad clicks
Expected result
Use this output to verify values, aliases, ordering, and row count.
| user_id |
|---|
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
| 8 |
| 9 |
| 10 |
Previewing 10 of 21 expected rows. Run the query in the editor to inspect the full result.
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics:
Continue practicing
Explore related company challenges
Meta
Independent Meta-style social-product, engagement, content, community, messaging, and advertising SQL practice.
Microsoft
Independent Microsoft-style cloud, productivity, subscription, usage, support, and customer analytics SQL practice.
Netflix
Independent Netflix-style streaming, subscription, catalog, ratings, and engagement SQL practice.
Return to the complete interview preparation experience.