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.

What is SQL compiler

The use of SQL compiler is it converts user written SQL statements using using SQL parsing engine and get us results from the RDBMS database.

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

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.