Databases · Middle · Question 67 of 75
What does SELECT DISTINCT ON (user_id) * FROM orders ORDER BY user_id, created_at DESC return?
- 1Only users with exactly one order
- ✓Correct answer: One row per user: the first by the given order, here the latest order
- 3All orders without duplicates
Explanation
DISTINCT ON is a PostgreSQL extension for 'latest per group'. The ORDER BY must start with the DISTINCT ON columns.