> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-8a08bda2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Documentation for the `EXISTS` operator

# EXISTS

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 also be used in a [WHERE](/reference/statements/select/where) clause.

<Tip>
  ***

  References to main query tables and columns are not supported in a subquery.
</Tip>

**Syntax**

```sql theme={null}
EXISTS(subquery)
```

**Example**

Query checking existence of values in a subquery:

```sql title="Query" theme={null}
SELECT EXISTS(SELECT * FROM numbers(10) WHERE number > 8), EXISTS(SELECT * FROM numbers(10) WHERE number > 11)
```

```text title="Response" theme={null}
┌─in(1, _subquery1)─┬─in(1, _subquery2)─┐
│                 1 │                 0 │
└───────────────────┴───────────────────┘
```

Query with a subquery returning several rows:

```sql title="Query" theme={null}
SELECT count() FROM numbers(10) WHERE EXISTS(SELECT number FROM numbers(10) WHERE number > 8);
```

```text title="Response" theme={null}
┌─count()─┐
│      10 │
└─────────┘
```

Query with a subquery that returns an empty result:

```sql title="Query" theme={null}
SELECT count() FROM numbers(10) WHERE EXISTS(SELECT number FROM numbers(10) WHERE number > 11);
```

```text title="Response" theme={null}
┌─count()─┐
│       0 │
└─────────┘
```
