Important
The SingleStore 9.1 release candidate (RC) is available now. It will be promoted to general availability (GA) soon and at that time it will be renamed to SingleStore 10.
In the interim, SingleStore 9.1 RC can be used to preview, evaluate, and provide feedback on the new and upcoming features in SingleStore 10, while SingleStore 9.0 is recommended for production workloads.
EXISTS AND NOT EXISTS
On this page
The EXISTS and NOT EXISTS command use a subquery to determine whether the subquery returns any rows.
Syntax
SELECT column-list FROM table WHERE
{ EXISTS | NOT EXISTS }
( SELECT column FROM table WHERE condition )Remarks
-
If the subquery returns any records,
EXISTSsubquery returnsTRUEandNOT EXISTSsubquery returnsFALSE. -
If the subquery returns no records,
NOT EXISTSsubquery returnsTRUEandEXISTSsubquery returnsFALSE. -
SingleStore supports
[NOT] EXISTSwith and without correlated queries.
Examples
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 employeeWHERE EXISTS ( SELECT * FROM managerWHERE employee.name = manager.name);
+---------------+
| Name |
+---------------+
| Adam Weaver |
| Leslie Winkle |
| Chris Palms |
| Joanna Miles |
+---------------+The following query lists all the stock_
SELECT stock_symbolFROM tradeWHERE NOT EXISTS ( SELECT * FROM companyWHERE symbol = stock_symbol) ;
+--------------+
| stock_symbol |
+--------------+
| ZPNM |
| WQOP |
+--------------+Last modified: