Quantcast
Channel: SQL Archives - SQL Authority with Pinal Dave
Viewing all articles
Browse latest Browse all 594

SQL SERVER – Logical Processing Order of the SELECT Statement

$
0
0

Earlier this week, I have discussed SQL SERVER – TOP and DISTINCT – Epic Confusion. I got lots of feedback on this blog post and lots of people wrote emails asking about why the result we get is the result we get. The answer is very simple – it is because of the Logical Processing Order of the SELECT Statement.

SQL SERVER - Logical Processing Order of the SELECT Statement logicalorder-800x235

The most asked question was which keyword or operator is processed first – DISTINCT or TOP. Well, the answer is very simple and it is given in detail on Microsoft’s website over here.

Here is the list of all the logical processing orders.

  1. FROM
  2. ON
  3. JOIN
  4. WHERE
  5. GROUP BY
  6. WITH CUBE or WITH ROLLUP
  7. HAVING
  8. SELECT
  9. DISTINCT
  10. ORDER BY
  11. TOP

While what you see is the logical processing order, the physical processing order is different from it. However, this order should give you an idea of how the query will work logically and will give results accordingly.

Here is the video which started all the conversation related to the logical processing order.

You can find the code of the video listed above in this blog post SQL SERVER – TOP and DISTINCT – Epic Confusion.

If you like the blog post, you can always follow my YouTube channel where you can see many similar videos.

Reference: Pinal Dave (https://blog.sqlauthority.com

First appeared on SQL SERVER – Logical Processing Order of the SELECT Statement


Viewing all articles
Browse latest Browse all 594

Trending Articles