AdBlock Detected!
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.
SQL EXISTS |
|
SQL > Advanced SQL >
Exists
EXISTS is a Boolean operator used in a subquery to test whether the inner query returns any row. If it does, then the outer query proceeds. If not, the outer query does not execute, and the entire SQL statement returns nothing. SQL EXISTS is a Boolean operator used with subqueries: it returns TRUE if the inner query returns at least one row, allowing the outer query to execute — and FALSE (returning nothing) if the inner query returns no rows.
SyntaxThe syntax for EXISTS is: Please note that instead of *, you can select one or more columns in the inner query. The effect will be identical. ExampleWe use the following tables for our example. Table Store_Information
Table Geography
The following SQL query, produces the result below:
At first, this may appear confusing, because the subquery includes the [region_name = 'West'] condition, yet the query summed up sales for stores in all regions. Upon closer inspection, we find that since the subquery returns more than zero row, the EXISTS condition is true, and the rows returned from the query "SELECT SUM(Sales) FROM Store_Information" become the final result. Frequently Asked Questions
|
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.