Tags / greatest-n-per-group
Finding the Second Largest Value in a Grouped Dataset Using SQL and Ranking Functions
Querying Single Rows in a Table with Multiple Rows in a Subquery Using Row Number and Aggregate Functions
Selecting the Maximum Time from a DateTime Column Group by Another DateTime Column Using PostgreSQL's DISTINCT ON Clause
Retrieving the Second Newest Record in SQL Queries Using Window Functions
Joining Two Tables and Getting the Most Recent Records for a Given Name: A SQL Solution Using Correlated Subqueries
SELECT DISTINCT ON (label) * FROM products ORDER BY label, created_at DESC;
Understanding the Limitations of ROW_NUMBER() and Finding Alternative Solutions for Partitioned Data
Using Window Functions in MySQL: Fetching Last N Rows for Multiple Users
Finding the First Row for Each ID-Grade Combination Using Window Functions in MySQL