1052
MySQLERRORCommonQuery SyntaxHIGH confidence

Column in field list is ambiguous

What this means

Error 1052 (SQLSTATE 23000) is raised when a column name referenced in a SELECT, WHERE, or ORDER BY clause exists in more than one table involved in a JOIN and is not qualified with a table alias or table name.

Why it happens
  1. 1Two or more joined tables share a column name (e.g. both have an id or name column)
  2. 2Column reference is unqualified — no table prefix or alias
How to reproduce

A SELECT with a JOIN where the column name appears in multiple tables.

trigger — this will error
trigger — this will error
SELECT id, name
FROM orders
JOIN customers ON orders.customer_id = customers.id;
-- 'id' and 'name' exist in both tables

expected output

ERROR 1052 (23000): Column 'id' in field list is ambiguous

Fix

Qualify every ambiguous column with a table alias

WHEN Always — qualify columns in multi-table queries.

Qualify every ambiguous column with a table alias
SELECT o.id AS order_id, c.id AS customer_id, c.name
FROM orders o
JOIN customers c ON o.customer_id = c.id;

Why this works

Prefixing columns with a table alias removes ambiguity. Assigning aliases to result columns also prevents confusion in application code.

What not to do

Use SELECT * in multi-table JOINs

Returns duplicate column names and masks ambiguity errors until they surface as bugs.

Sources
Official documentation ↗

MariaDB Server error code 1052 / ER_NON_UNIQ_ERROR

MariaDB JOIN Syntax

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MySQL errors