Where vs having

Source: Internet
Author: User

Differences between where and having:

The where clause cannot contain clustering functions, because it is meaningless to try to use clustering functions to judge the input rows to clustering operations. Conversely, having clauses always contain aggregate functions.
Having generally follows group by and executes part of the selected record group to work.
Where is used to execute all data. In addition, having can be used as an aggregate function, such as having sum (qty)> 1000.
1. Use different places
Where can be used in select, update, delete, and insert... into statements.
Having can only be used in select statements.
2. The execution sequence is different.
The where search condition is applied before the statement is executed for grouping.
Having search conditions are executed after grouping conditions.
That is, if where and having are used together, where will be executed first, having will be executed later.
3. clauses are different
The conditional expression having in the WHERE clause can be followed, while some expressions in the having clause cannot be followed. The having clause can use a set function (sum, Count, AVG, Max, and min ), the where clause is not allowed.
4. Different objects
The where clause acts on tables and views, and the having clause acts on groups.

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.