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:
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.