MySQL any,some all (ZZ)

Source: Internet
Author: User

Reprinted from: http://blog.csdn.net/netcy/article/details/8464503

A common use of the all and any operators is to test the results of a data-only query with a relative comparison operator. They test whether the comparison value matches all or part of the value returned by the subquery. For example, if the comparison value is less than or equal to each value returned by the subquery, <= all will be true, and if the comparison value is less than or equal to any one of the values returned by the subquery, <= any will be true. Some is a synonym for any.

Example:

CREATE TABLE s1 (id int);

CREATE TABLE t1 (id int);

INSERT into S1 select 1;

INSERT into S1 select 2;

INSERT into S1 select 3;

INSERT into T1 select 1;

INSERT into T1 select 2;

INSERT into T1 select 3;

Select S1.id from S1 where S1.id>any (select t1.id from T1)

The returned result is:

2

3

Select S1.id from S1 where S1.id>=any (select t1.id from T1)

The returned result is:

1

2

3

When the all, any, or some operators are used in conjunction with the "=" comparison operator, the subquery can be a data table subquery. At this point, you need to use a data row constructor to provide a comparison value that is compared to the data rows returned by the subquery.

MySQL any,some all (ZZ)

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.