mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-16 20:53:27 +00:00
da76c4053c
Co-authored-by: gyuton <40863448+gyuton@users.noreply.github.com>
32 lines
828 B
Markdown
32 lines
828 B
Markdown
# EXISTS {#exists-operator}
|
|
|
|
The `EXISTS` operator checks how many records are in the result of a subquery. If it is empty, then the operator returns `0`. Otherwise, it returns `1`.
|
|
|
|
`EXISTS` can be used in a [WHERE](../../sql-reference/statements/select/where.md) clause.
|
|
|
|
!!! warning "Warning"
|
|
References to main query tables and columns are not supported in a subquery.
|
|
|
|
**Syntax**
|
|
|
|
```sql
|
|
WHERE EXISTS(subquery)
|
|
```
|
|
|
|
**Example**
|
|
|
|
Query:
|
|
|
|
``` sql
|
|
SELECT 'Exists' WHERE EXISTS (SELECT * FROM numbers(10) WHERE number < 2);
|
|
SELECT 'Empty subquery' WHERE EXISTS (SELECT * FROM numbers(10) WHERE number > 12);
|
|
```
|
|
|
|
The first query returns one row while the second query does not return rows because the result of the subquery is empty:
|
|
|
|
``` text
|
|
┌─'Exists'─┐
|
|
│ Exists │
|
|
└──────────┘
|
|
```
|