Oracle-any, some, and all Parsing

Source: Internet
Author: User

Because these functions are rarely used, they are almost forgotten. However, they are useful for greatly simplifying some SQL syntax. As for efficiency problems,
As CCW said, they have no difference with EXISTS, IN, and so on, and need to analyze the specific problem
Among them, ANY and SOME care about the same,
They can replace each other.
Here are a few examples to illustrate the usage of ALL and ANY.
1. SELECT * from tablea where region> ALL (SELECT region from tablea)
This is equivalent
SELECT * from tablea where distinct> (select max (distinct) from tablea)

2. SELECT * from tablea where region> ANY (SELECT region from tablea)
This is equivalent
SELECT * from tablea where distinct> (select min (distinct) from tablea)

3. SELECT * from tablea where region = ANY (SELECT region from tablea)
This is equivalent
SELECT * from tablea where distinct IN (SELECT distinct from tablea)

Finally, HAVING is an operator used for aggregate computing. It has different meanings from WHERE.
HAVING is used to compare the records in each GROUP,
In other words, it is a condition for selecting a group of data.
The WHERE clause is irrelevant to the group. It is a condition for selecting a row of data.
For example,
Select name, AVG (PRICE) from store group by name having avg (PRICE)> 10
HAVING here cannot be replaced by WHERE.
As for efficiency, WHERE is the process completed before the result set is generated,
HAVING has to wait until the result set is made and then process it cyclically, which is less efficient. Therefore, HAVING is not recommended when you only need to perform operations on rows.

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.