EXISTS Limit Method

Source: Internet
Author: User

In the previous example, we usedINTo retrieve the internal and external queries. In addition, multiple methods, such as >,<,=, can be used for internal queries and external queries.EXISTSIt is also one of the methods. We will discuss this forumEXISTS.

Basically,EXISTSIt is used to check whether any results have been produced in internal queries. If yes, the system displays the SQL statements in the external query. If nothing exists, the entire SQL sentence will not produce any results.

EXISTSThe signature method is:

SELECT "digit 1"
FROM "table 1"
WHERE EXISTS
(SELECT *
FROM "Table 2"
WHERE [condition])

In the internal query, we do not necessarily use * to select all the positions. We can also select any digit in table 2. The last result of these two practices is the same.

Let's look at an example. We have the following two tables:

Store_InformationTable

Store_name Sales Date
Los Angeles $1500 Jan-05-1999
San Diego $250 Jan-07-1999
Los Angeles $300 Jan-08-1999
Boston $700 Jan-08-1999

 

GeographyTable

Region_name Store_name
East Boston
East New York
West Los Angeles
West San Diego

 

The SQL statements we entered are:

Select sum (Sales) FROM Store_Information
WHERE EXISTS
(SELECT * FROM Geography
WHERE region_name = 'west ')

We will get the following answer:

 

SUM (Sales)
2750

At first glance, this answer seems to be incorrect, because the internal query contains a [region_name = 'west'] condition, however, the last answer does not include this condition. In fact, there is no problem. In this example, the internal query produces more than one item, soEXISTSThe condition is valid, so the external query token is rejected. The parameter does not contain [region_name = 'west.

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.