Where can I find the processing order for a select statement?

  • I've tried searching this site, because I know people have made reference to this. The closest I could come with BOL was the following (but this is incomplete):

    Processing Order of WHERE, GROUP BY, and HAVING Clauses

    The following steps show the processing order for a SELECT statement with a WHERE clause, a GROUP BY clause, and a HAVING clause:

    1 The FROM clause returns an initial result set.

    2 The WHERE clause excludes rows not meeting its search condition.

    3 The GROUP BY clause collects the selected rows into one group for each unique value in the GROUP BY clause.

    4 Aggregate functions specified in the select list calculate summary values for each group.

    5 The HAVING clause additionally excludes rows not meeting its search condition.

  • yep, what you posted matches what i have in my snippets, captured from some other post on the same subject:

    The main clauses in SQL are logically executed in the following order:

    FROM (including JOINS)

    WHERE

    GROUP BY

    HAVING

    SELECT

    DISTINCT

    ORDER BY

    TOP

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thanks, Lowell, that's helpful.

    Julie

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply