Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumSQLwindow functions ROW_NUMBER RANKSingle-choice MCQ

You want exactly one row per customer (their latest order) using ROW_NUMBER. Why must the ROW_NUMBER call sit in a subquery/CTE rather than be filtered directly in WHERE?

SELECT * FROM orders WHERE ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY created_at DESC) = 1;