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

> Documentation for EXISTS Statement

# EXISTS

```sql theme={null}
EXISTS [TEMPORARY] [TABLE|DICTIONARY|DATABASE] [db.]name [INTO OUTFILE filename] [FORMAT format]
```

Returns a single `UInt8`-type column, which contains the single value `0` if the table or database does not exist, or `1` if the table exists in the specified database.

<h2 id="subquery-form">
  Subquery form
</h2>

The `EXISTS` operator checks whether a subquery returns any rows. It returns `0` if the subquery result is empty; otherwise, it returns `1`.

You can use `EXISTS` in a [`WHERE`](/reference/statements/select/where) clause. The subquery cannot reference tables or columns from the outer query.

**Syntax**

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

**Examples**

Check whether a subquery returns rows:

```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 │
└───────────────────┴───────────────────┘
```

Use `EXISTS` in a `WHERE` clause with a subquery that returns 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 │
└─────────┘
```

When the subquery result is empty, `EXISTS` returns `0`:

```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 │
└─────────┘
```
