SQL Order Of Operations
For SQL select statements, with only one select operation, the order of operations is: from, join, where, group by, having, select, distinct, order by and limit.
Note that on clauses are parts of join operations, and, windows are parts of select operations. Note also that can have a where clause operate on the results of a join operation, but, not on the results of a group by operation!