Join to pick latest row per group
SQL
Medium
2 views
Problem Description
For each customer, show details of their latest order (not just id).
Sample Test Case
Output:
Latest order rows
Constraints
Use window function
Official Solution
SELECT * FROM (SELECT o.*, ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY order_date DESC, order_id DESC) AS rn FROM Orders o) t WHERE rn = 1;
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!