SQL What is the correct order of execution ?

 What is the correct order of execution ?


  1. FROM
  2. WHERE
  3. GROUP BY
  4. HAVING
  5. ORDER BY
  6. SELECT

Can you share your knowledge on difference between WHERE clause and HAVING clause ?




Where - we will use to set conditions
Having - we will use to set conditions for group by values


why WHERE clause is before GROUP BY clause , why not after ?


Once you grouped the values then you cant use where clause, you only have to use having clause. So it should always be front of it






Comments