LATERAL top-N
LATERAL lets a subquery in FROM use columns of the tables to its left, so 'top N per group' becomes a short query with LIMIT.
task
For each of the 5 customers with most orders (ties by lower id), their 3 latest orders.
Run a query to see rows here.
Run EXPLAIN on the statement under the cursor: Plan tab, button Explain.
No tables yet.
LATERAL lets a subquery in FROM use columns of the tables to its left, so 'top N per group' becomes a short query with LIMIT.
For each of the 5 customers with most orders (ties by lower id), their 3 latest orders.