Rank rows within an ordered result.
Section: CTEs and window functions
Assign row numbers
sql
sql
SELECT id, email, ROW_NUMBER() OVER (ORDER BY created_at DESC) AS row_num
FROM users;Explanation
Useful for ordered reports and deterministic pagination helpers.
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 CTEs and window functions