Introduction
LATERAL subqueries let you use columns from a table in a subquery next to it. This helps when you want to find related data for each row easily.
You want to find the top 1 related record for each row in a table.
You need to join each row with a set of rows that depend on that row's values.
You want to calculate something for each row using a subquery that uses that row's data.
You want to simplify complex joins by using a subquery that can see the outer row.