SQL Server Interview: What is the logical order of SQL Query (SELECT Statement)

I have already shared hundreds of SQL Server Interview Questions.
Here, I would like to share one more common and important SQL Interview question for SQL Beginner.

Whenever I am taking the SQL Beginner’s Interview, I always ask one question “What is the logical order of SQL Query or SELECT Statement”.

It looks like a very basic question, but It is very important to know about the sequence of query execution because It plays main role in query optimization.

You should know that JOINS are executing the first or WHERE clause is executing the first. Both are filtering the data, but most of the time I have found a wrong answer.

Below is a correct logical order of SQL Query or SELECT Statement:

  • FROM
  • ON
  • JOIN
  • WHERE
  • GROUP BY
  • WITH CUBE or WITH ROLLUP
  • HAVING
  • SELECT
  • DISTINCT
  • ORDER BY
  • TOP
Anvesh Patel

Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz