# Column reference is ambiguous / Column 'id' in field list is ambiguous (MySQL 1052)

**Code:** `ambiguous column` · **Category:** SQL · **Seen on:** MySQL, PostgreSQL, SQL, PHP

A column name exists in more than one joined table, so the database doesn’t know which one you mean.

## Meaning

After a JOIN, unqualified names like `id`, `name` or `created_at` usually exist in several tables. Qualify them with the table name or alias.

## Common causes

- Unqualified column in SELECT/WHERE/ORDER BY after a JOIN
- Same column name in a subquery and outer query
- ORM building raw where clauses without table prefixes

## Quick fix

1. Prefix columns with table aliases (`u.id`, `o.id`)
2. Alias output columns that share names (`o.id AS order_id`)

## Detailed fix by platform

### SQL

1. Qualify every column in joins:

```sql
SELECT u.id AS user_id, o.id AS order_id, o.total
FROM users u
JOIN orders o ON o.user_id = u.id
WHERE o.status = 'paid'
ORDER BY o.created_at DESC;
```


### PHP

1. Laravel: `->where('orders.status', 'paid')` instead of `->where('status', 'paid')` on joined queries.

## How to diagnose

1. **Column** — Which column is named?
2. **Tables** — Which joined tables contain it?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/sql/column-reference-is-ambiguous)
