Categories

.NET (1) CSS (5) OOP (1) PHP (2) SQL (5) SQL Server (8) TSQL (1)

Monday, December 20, 2010

SQL Writing and Execution Order

I'm writing this post because developers often get confused about the SQL clauses execution order. The most important and basic SQL clauses are 
  • SELECT
  • FROM
  • WHERE
  • GROUP BY
  • HAVING
  • ORDER BY 
And there order in SQL query is
  1. SELECT
  2. FROM
  3. WHERE
  4. GROUP BY
  5. HAVING 
  6. ORDER BY
 But the database engine processes them in different ways. And the order of these clauses in DB is
  1. FROM
  2. WHERE
  3. GROUP BY
  4. HAVING
  5. SELECT
  6. ORDER BY

No comments:

Post a Comment