# 47: UNKNOWN_IDENTIFIER (code 47)

> A column or alias in SELECT, WHERE or ORDER BY does not exist in the tables the query sees.

Source: https://sqlly.app/errors/clickhouse/unknown-identifier
Last updated: 2026-11-30
License: Text and data [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) (credit SQLly, sqlly.app); code and SQL snippets [MIT](https://opensource.org/license/mit). [Details](https://sqlly.app/license).
Note: Quoted error message text belongs to its database vendor.

- Error code: `47`
- Name: `UNKNOWN_IDENTIFIER`
- Category: Syntax and parsing

Error message:

```text
Unknown expression identifier `{identifier}`. In scope {query}.
```

## What it means

`UNKNOWN_IDENTIFIER` (47) is raised during analysis when a name cannot be resolved to any column, alias or CTE. The SQL parsed fine (that would be 62); the names do not line up. It is the ClickHouse twin of `no such column`.

## Common causes

- A misspelled or differently cased column name.
- The column exists on a different table than the one the query reads.
- An alias is referenced outside the clause that defines it, or an upstream schema change renamed the column.

## How to fix it

1. Check the real column names and their case.

   ```sql
   SELECT name FROM system.columns WHERE database = 'my_db' AND table = 'my_table';
   ```
2. Qualify the column with the table name. An unqualified column that exists in both joined tables did not raise code 47 on 26.9.3.38; it resolved to the left table.

   ```sql
   SELECT o.id FROM orders o JOIN users u ON o.user_id = u.id;
   ```
3. When a materialized view depends on a renamed column, add the new column to the view's target table first, then change its SELECT. MODIFY QUERY fails with code 16 (NO_SUCH_COLUMN_IN_TABLE) when the target lacks the column. A view with an implicit target was not tested here.

   ```sql
   ALTER TABLE my_mv MODIFY QUERY SELECT id, new_name FROM my_table;
   ```

## Reproduce it safely

```sql
CREATE TABLE scratch_c (id UInt32) ENGINE = MergeTree ORDER BY id; then run SELECT nope FROM scratch_c to get code 47.
```

## How SQLly helps

SQLly's Validate SQL (Cmd+Shift+V on macOS, Ctrl+Shift+V on Windows and Linux) marks column names the connected ClickHouse schema does not have.

## Questions

### Is this the same as SYNTAX_ERROR?

No. 62 means the token stream could not parse. 47 means it parsed and a name did not resolve.

### Why do aliases in WHERE fail sometimes?

In ClickHouse 26.9 an alias from the same SELECT resolves in WHERE, in PREWHERE and inside aggregate arguments. Aggregate functions are still not allowed in WHERE; that fails with code 184 ILLEGAL_AGGREGATION.

## Related errors

- [`60`](https://sqlly.app/errors/clickhouse/table-not-exists): UNKNOWN_TABLE (code 60)
- [`62`](https://sqlly.app/errors/clickhouse/syntax-error): SYNTAX_ERROR (code 62)

The code and message text are from the [ClickHouse documentation (system.errors)](https://clickhouse.com/docs/en/operations/system-tables/errors).
