SQL order of operation cheat sheet

OrderClauseDescription
1FROMChoose your tables from where to get the data
2JOINJoin matching data between tables
3WHEREFilters the data
4GROUP BYAggregates the data
5HAVINGFilters the aggregated data
6SELECTReturns the selected columns you choose
7ORDER BYSorts the final data

This is meant to be a quick reference. One could write a book about each item in detail.
When tuning your SQL, start from the top and go to the bottom. Utilize built in execution plan feature to identify costly operations.

Leave a Reply

Your email address will not be published. Required fields are marked *