Databases · Middle · Question 67 of 75

What does SELECT DISTINCT ON (user_id) * FROM orders ORDER BY user_id, created_at DESC return?

Explanation

DISTINCT ON is a PostgreSQL extension for 'latest per group'. The ORDER BY must start with the DISTINCT ON columns.

Further reading

Problem with a question

Databases · Middle · question 67

Test yourself

Take the Databases · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz