[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"$f1jptot400gi0w":3},{"_id":4,"slug":5,"title":6,"subtitle":7,"kind":8,"cards":9,"tags":22,"categories":24,"source":26,"lang":29,"author":30,"audioState":33,"stats":34,"publishedAt":37,"renderer":38},"6ab9f809ca21c797c7e97332","understanding-sql-execution-order-eda3305f","Understanding SQL Execution Order","When we write an SQL query, we usually read it from top to bottom.","news",[10,12,17],{"headline":6,"body":7,"imageUrl":11,"sourceImageUrl":11},"https:\u002F\u002Fmedia2.dev.to\u002Fdynamic\u002Fimage\u002Fwidth=1200,height=627,fit=cover,gravity=auto,format=auto\u002Fhttps%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvyt000sr7rkrol673jiz.png",{"headline":13,"body":14,"imageUrl":15,"images":16},"But the database does not process this query","But the database does not process this query exactly in the same order that we write it. Understanding the execution order helps us understand how databases process our queries and why some queries are faster than others. ===========SQL Execution Order=========== A simple way to remember the logical execution order is: FROM First, the database finds the table that we want to use. The database starts with the employees table. If we use a JOIN, the database also needs to combine the required tables. WHERE Next, the database filters the rows. Only employees whose salary is greater than 50000 are kept. This step can remove a large number of rows before the next steps. GROUP BY Next, the database groups the remaining rows. Here, employees are grouped by department. HAVING HAVING filters the groups created by GROUP BY. Here, only departments with more than 10 employees are returned.","\u002Fapi\u002Fmedia\u002Fposts\u002Funderstanding-sql-execution-order-eda3305f\u002F1.webp",{"local":15},{"headline":18,"body":19,"imageUrl":20,"images":21},"Difference between WHERE and HAVING. SELECT After filtering","Difference between WHERE and HAVING. SELECT After filtering and grouping, the database produces the columns requested in the SELECT. DISTINCT DISTINCT removes duplicate results. ORDER BY ORDER BY sorts the final result. The employees are sorted from the highest salary to the lowest salary. LIMIT \u002F OFFSET Finally, LIMIT controls how many rows are returned. Only the first 10 rows are returned. OFFSET can be used to skip rows. For further actions, you may consider blocking this person and\u002For reporting abuse","\u002Fapi\u002Fmedia\u002Fposts\u002Funderstanding-sql-execution-order-eda3305f\u002F2.webp",{"local":20},[23],"dev",[25],"Technology",{"name":27,"url":28},"Dev.to","https:\u002F\u002Fdev.to\u002Fbuddika_b\u002Funderstanding-sql-execution-order-3clo","en",{"handle":31,"displayName":32},"spots","Spots","queued",{"views":35,"likes":36,"saves":36,"shares":36,"completions":36,"opens":36,"skips":36,"depthSum":36},5,0,"2026-09-28T05:15:53.761Z","local"]