ambiguous column 🗃️ SQL

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

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

Seen on: MySQL PostgreSQL SQL PHP

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?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.