Find latest order per customer using subquery
SQL
Medium
4 views
Problem Description
Return orders that are the latest order for each customer.
Sample Test Case
Input:
Orders(customer_id, order_date)
Constraints
Use correlated max
Official Solution
SELECT o.* FROM Orders o WHERE o.order_date = (SELECT MAX(x.order_date) FROM Orders x WHERE x.customer_id = o.customer_id);
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!