Watch the 7.3 Webinar On-Demand
This new release brings updates to Universal Storage, query
optimization, and usability that you won’t want to miss.
Used with a subquery to check if the subquery returns a record.
SELECT column-list FROM table WHERE
{ EXISTS | NOT EXISTS }
( SELECT column FROM table WHERE condition )
EXISTS
subquery returns TRUE
and NOT EXISTS
subquery returns FALSE
.NOT EXISTS
subquery returns TRUE
and EXISTS
subquery returns FALSE
.[NOT] EXISTS
with and without correlated queries.The following query lists the name of all the employees in the employee table that have a record in the manager table.
SELECT employee.name AS 'Name'
FROM employee
WHERE EXISTS ( SELECT * FROM manager
WHERE employee.name = manager.name
);
****
+---------------+
| Name |
+---------------+
| Adam Weaver |
| Leslie Winkle |
| Chris Palms |
| Joanna Miles |
+---------------+
The following query lists all the stock_symbol values in the trade table which do not match the values in the stock field in the company table.
SELECT stock_symbol
FROM trade
WHERE NOT EXISTS ( SELECT * FROM company
WHERE symbol = stock_symbol
) ;
****
+--------------+
| stock_symbol |
+--------------+
| ZPNM |
| WQOP |
+--------------+