Keep one row per business key and remove duplicates logically.
Section: Pagination, Deduplication, and Search Patterns
Deduplicate rows with ROW_NUMBER
sql
sql
WITH ranked AS (
SELECT *,
ROW_NUMBER() OVER (PARTITION BY email ORDER BY created_at DESC) AS rn
FROM users
)
SELECT *
FROM ranked
WHERE rn = 1;Explanation
Useful for data cleanup and canonical row selection.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Pagination, Deduplication, and Search Patterns
Use keyset pagination
Paginate by a stable cursor instead of a large OFFSET.
Search across multiple columns
Apply a simple wildcard search over several text fields.
Explain with runtime stats
Run a query and collect timing or actual row information where supported.