Keep The Newest Signup
signups:
| id | created_at | |
|---|---|---|
| 1 | a@x | 2026-01-02 |
| 2 | b@x | 2026-01-03 |
| 3 | a@x | 2026-01-05 |
| 4 | c@x | 2026-01-06 |
| 5 | a@x | 2026-01-07 |
WITH ranked AS (
SELECT id, email,
row_number() OVER (PARTITION BY email
ORDER BY created_at DESC, id DESC) AS rn
FROM signups
)
SELECT id FROM ranked WHERE rn = 1 ORDER BY id;
Which ids come back?
Sign in to answer questions and track your progress
Sign In