Understanding execution order of SQL queries!
Before you can optimize SQL queries, you must understand their order of execution!
The order of execution is different from how you write it, here's the actual order:
1οΈβ£ FROM: Determines the tables of interest
2οΈβ£ JOIN: Joins the tables of interest as per specification and sets up the base data.
2οΈβ£ WHERE: Applies a filter to the rows returned from the FROM clause. It restricts the result set to only those rows that meet a specified condition
3οΈβ£ GROUP BY: Groups rows that have the same values in specified columns. It is often used with aggregate functions ( eg. COUNT, MAX, MIN, SUM, AVG) to perform calculations on each group.
4οΈβ£ HAVING: Similar to the WHERE clause, but it is used to filter groups based on aggregate functions. It is applied after the GROUP BY clause.
5οΈβ£ SELECT: Used to specify the columns from the filtered results to display in the query's result set. It can include column names, aggregate functions, and expressions.
6οΈβ£ ORDER BY: Sorts the result set returned by the query in ascending (ASC) or descending (DESC) order based on one or more columns.
7οΈβ£ LIMIT: Restricts the number of rows returned by the query.
_________
That's a wrap!
If you interested in:
β’ Python π
β’ ML/MLOps π
β’ CV/NLP π£
β’ LLMs π§
β’ AI Engineering βοΈ
Find me β
@akshay_pachaar βοΈ
Everyday, I share tutorials on above topics!
I also write a weekly Newsletter on AI Engineering, link in the next tweet!
Cheers!! π