Whenever we write any SQL query , we always think about the result set which it will produce. However it is equally important to understand how the result set is built whenever any SQL Query is executed. For this, we should know the order of execution of any SQL Query. The standard format of any SQL Query is like :
SELECT column_name FROM table_name WHERE column='condition' ORDER BY columns GROUP BY column_names HAVING some_condition;
Here we can see that there are several SQL clauses used in the query. However knowledge of order in which these SQL Clauses are executed is important. So, first WHERE clause is executed , then GROUP BY followed by HAVING. Once the data is ready then ORDER BY sorts the data and then SELECT clause is executed to retrieve only those columns which are specified.
So the order is:
WHERE-->GROUP BY-->HAVING-->ORDER BY-->SELECT