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

You need exactly one row per customer (their most recent order) with no gaps in numbering even when two orders share the same timestamp. Which window function and ordering guarantees a single deterministic winner per partition?

SELECT * FROM ( SELECT o.*, <FUNC> OVER (PARTITION BY customer_id ORDER BY created_at DESC, order_id DESC) AS rn FROM orders o ) t WHERE rn = 1;