Select -- from -- where -- group by -- having -- order by is ordered sequentially. The difference between where and having

Source: Internet
Author: User

Select -- from -- where -- group by -- having -- order by is ordered sequentially. The difference between where and having

1. the keywords used in the query mainly include six, and their order is
Select -- from -- where -- group by -- having -- order
Select and from are mandatory, and other keywords are optional. The execution sequence of these six keywords
The writing sequence is not the same as that of the SQL statement, but is executed in the following order.
From -- where -- group by -- having -- select -- order,
From: The data table from which data is to be retrieved.
Where: Filter table data Conditions
Group by: How to group the data filtered out above
Having: filtering conditions for the data already grouped above
Select: Check the column in The result set or the calculation result of the column.
Order by: in which order to view the returned data

2. Table association after from is parsed from right to left
The resolution sequence of the where condition is bottom-up.
That is to say, when writing SQL files, try to put tables with a large amount of data on the rightmost side for association,
Put the conditions that can filter out a large amount of data at the bottom of the where statement.

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.