PostgreSQL ยท SQL foundations
SQL text order is not evaluation order
The written query begins with SELECT, but reason about a basic query in this logical order:
FROM builds the input, WHERE filters rows, GROUP BY forms groups, HAVING filters groups,
then the select list computes output columns. ORDER BY sorts that output and LIMIT trims it.
This is a reasoning model, not a promise about the physical execution plan. PostgreSQL's optimizer can rearrange work while preserving the query's semantics.