What is SQL?
SQL stands for Structured Query Language. It allows you to manipulate and structure databases to fit your needs. Today, we will discuss the Order of Operations in SQL. Importantly, the coding order (how you write a query) is different from the execution order (how the database processes it).
First things first - What is the coding order?:
Query Syntax Order
- SELECT
- Selects the columns or calculated values and returns them in the final result.
- FROM
- Chooses the table from which the data will be accessed.
- WHERE
- Filters the records accessed from the From clause based on the specified conditions.
- GROUP BY
- Groups the filtered records by specified columns to perform aggregations.
- HAVING
- Applies filters to the grouped data, keeping only the groups that meet a certain conditions.
- ORDER BY
- Sorts the result set based on specified columns in ascending or descending order.
![](https://www.thedataschool.co.uk/content/images/2025/01/image-154.png)
Order of Execution
- FROM
- WHERE
- GROUP BY
- HAVING
- SELECT
- ORDER BY
- ORDER BY
Key Points:
- Query Syntax Order: How the query is written by the user.
- Order of Execution: How the database internally processes the query.