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

Author: Srini

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

Start Discussion

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.