The Order of SQL Query Execution Read Today

SQL Query executes in a particular order. The Query execution is a shadow to any developer. In this post, I have explained the execution flow of the SQL query.

Order of SQL statements

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

More on SQL Execution

Sample SQL

SELECT id,
       language,
       author creator
FROM proglang_tbl
ORDER BY creator;
In the above SQL, first FROM executes, next SELECT and the last is ORDER BY. See the below video for all clauses.

Video on SQL Order of Execution

Why ORDER BY is Last

In any database, the ORDER BY executes at the end. That means Sorting takes place only at the end.
Advertisements