Back to Practice
#0189

First Purchase Date per User

EasySQL15 min10 XP

Problem

Return each user_id and their first purchase_date from purchases.

Why This Matters

First-event queries power cohorts, retention analysis, onboarding funnels, and lifecycle reporting.

Schema

purchases(user_id INTEGER, purchase_date TEXT)

Examples

Example 1
Inputuser 1 purchases on Jan 5 and Jan 1; user 2 on Jan 3
Output1 -> 2026-01-01, 2 -> 2026-01-03

MIN date gives the first purchase per user.

Constraints

  • Return the exact requested result.
  • Handle common edge cases.
  • Keep the solution readable before optimizing.
CodeSQL
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Inputuser 1 purchases on Jan 5 and Jan 1; user 2 on Jan 3
Expected1 -> 2026-01-01, 2 -> 2026-01-03

MIN date gives the first purchase per user.

Hidden Test Categories
minimal inputrepeated valueslarger realistic input