SQL Server where, group by, order by execution sequence

Source: Internet
Author: User
2012-02-07 19:39 First where Condition 1, then group by condition 2 again order by condition 3

If a GROUP BY clause is declared, the output is divided into different groups that match one or more values. If there is a HAVING clause, it eliminates those groups that do not meet the given criteria.

If the ORDER BY clause is declared, the returned rows are sorted in the order specified. If an ORDER by is not given, the data rows are given in the way that the system considers the fastest generation possible.

Although the complete syntax of the SELECT statement is more complex, its main clauses can be summarized as follows:
SELECT select_list
[Into new_table]
From Table_source
[WHERE search_condition]
[GROUP by Group_by_expression]
[Having search_condition]
[ORDER by order_expression [ASC | DESC]]
You can use the UNION operator between queries to combine the results of a query into a single result set.

In other words, order by is placed on the last side.

SQL Server where, group by, order by execution sequence

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.