"MySQL" in MySQL any,in,some,all differences

Source: Internet
Author: User

A subquery refers to nesting another SELECT statement in a SELECT statement.
Any,in,some,all is one of the sub-query keywords,

Any can be used with =, >, >=, <, <=, <> to represent equal, greater than, greater than, equal to, less than, less than or equal to, and not equal to any one of the data.

All can be used with =, >, >=, <, <=, <>, respectively, to represent all data equal to, greater than, greater than or equal to, less than, less than or equal to, and not equal to any of them.

The syntax for their subquery is as follows:

 Some all (subquery);

The Any,all keyword must be used with a comparison operator. The Any keyword can be interpreted as "returns true for any value in the column returned by the subquery if the comparison evaluates to True."
For example:

Select  from where >  any (Select from T2);

If there is a row in table T1 containing (ten), T2 contains (21,14,6), the expression is true, if T2 contains (20,10), or the table T2 is an empty table, the expression is false. If the table T2 contains (null,null,null), the expression is unkonwn.

All means "returns true for all values in the column returned by the subquery if the comparison evaluates to True"
For example:

Select  from where >  All (Select from T2);

Suppose a row in table T1 contains (10). If the table T2 contains ( -5,0,+5), the expression is true because 10 is larger than all three values found in T2. If the table T2 contains (12,6,null,-100), the expression is false because there is a value of 12 greater than 10 in T2. If the table T2 contains (0,null,1), the expression is unknown. If T2 is an empty table, the result is true.

 not  in is the alias of "<>all", the same usage.

The statement in is the same as "=any".

For example:

Select  from where =  any (Select from T2); Select  from where inch (Select from T2);

The statement some is an alias of any and uses the same.
For example:

Select  from where <>  any (Select from T2); Select  from where <> some (Select from T2);

In the above query some understanding is easy to "table T1 in some S1 and T2 table S1 unequal", this statement with any understanding is wrong.

"MySQL" in MySQL any,in,some,all differences

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.