Tags / greatest-n-per-group
SELECT DISTINCT ON (label) * FROM products ORDER BY label, created_at DESC;
Using Window Functions to Get the Highest Metric for Each Group
Retrieving Maximum Values: Sub-Query vs Self-Join Approach
Retrieving the Second Newest Record in SQL Queries Using Window Functions
SELECT DISTINCT ON (user_id, activity_type_id, EXTRACT(year FROM start_date_local))
Retrieving the Last Production Quantity from a MySQL Query: Two Solutions with Correlated Subqueries and row_number()