> ## Documentation Index
> Fetch the complete documentation index at: https://braintrust.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Subquery alias conflicts with column names

export const plans_0 = "Any"

export const deployments_0 = "Any"

export const data_plane_version_0 = undefined

export const use_case_0 = "Use case - Writing SQL queries where table aliases match column names"

<Note>
  **Applies to:**

  * Plan - {plans_0}
  * Deployment - {deployments_0}
  * {data_plane_version_0}
  * {use_case_0}
</Note>

## Summary

**Issue:** Queries fail with a `Field not found` error when a subquery's table alias matches a column name used inside the subquery.

**Cause:** The alias collides with the column of the same name, causing Braintrust SQL to fail resolving field references without indicating the naming conflict.

**Resolution:** Rename the subquery alias to a value that does not match any column name referenced in the query.

## Resolution steps

### If you see `Field not found` with a subquery alias

#### Step 1: Check for alias/column name collisions

Compare the alias assigned to your subquery against the column names inside it. A match between the alias and a column name causes the error.

```sql theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
-- Fails: alias 'metrics' conflicts with column 'metrics'
SELECT metric AS name, AVG(value)
FROM (
  SELECT metric, value
  FROM experiment('724d08ca-d04e-4a40-8dd7-ad52498cdea3')
  UNPIVOT (value FOR metric IN (metrics))
) AS metrics
WHERE name IS NOT NULL
GROUP BY name
```

#### Step 2: Rename the subquery alias

Change the alias to a value that does not match any column name in the subquery.

```sql theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
-- Works: alias 'unpivoted' does not conflict with any column name
SELECT metric AS name, AVG(value)
FROM (
  SELECT metric, value
  FROM experiment('724d08ca-d04e-4a40-8dd7-ad52498cdea3')
  UNPIVOT (value FOR metric IN (metrics))
) AS unpivoted
WHERE name IS NOT NULL
GROUP BY name
```

### Otherwise, if the error persists after renaming

#### Check all aliases in the query scope

Review every alias in the query — including column aliases and outer query references — to ensure none conflict with column names produced by any subquery.

#### Contact support

If no naming conflict is found and the error continues, contact Braintrust support with your full query and the experiment ID for investigation.
