Error codes › 1060
MySQL & MariaDB error 1060: Duplicate column name
Example from our test runs:
Duplicate column name 'id' (5.6.51) A table would end up with two columns of the same name: CREATE TABLE ... AS SELECT * over a join, a view over a join, or ALTER TABLE ADD of a column that already exists.
| MySQL | MariaDB | |
|---|---|---|
| Symbol | ER_DUP_FIELDNAME | ER_DUP_FIELDNAME |
| SQLSTATE | 42S21 | 42S21 |
| Type | Server error | Server error |
| Versions | every release since 5.0 active | every release since 5.5 active |
What it means
Column names must be unique within a table or view. The statement would produce a second column with a name that is already used.
Why it happens
CREATE TABLE report AS SELECT * FROM emp JOIN dept …(orCREATE VIEWover the same) when both tables haveidorname. A plainSELECT *over the join is fine because result sets may repeat names; a table can’t.ALTER TABLE … ADD COLUMNin a migration that already ran.- A derived table such as
SELECT * FROM (SELECT a.id, b.id FROM a JOIN b …) xrepeats a name too. - The read-side cousin is 1052 “Column ‘id’ in field list is ambiguous”: the same clash, in a query that names the column without a table prefix.
How to fix it
- Don’t use
*over a join when the result is stored: list the columns and alias the clashing ones (emp.id AS emp_id, dept.id AS dept_id). - For migrations, check first:
SELECT 1 FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'emp' AND column_name = 'name';. MariaDB also hasADD COLUMN IF NOT EXISTS; MySQL doesn’t.
Reproduce it yourself
These steps are the exact test our harness runs. Use a scratch server, never production.
Connect with
mysql -u root -pand create a scratch database and the test data:CREATE DATABASE demo; USE demo; CREATE TABLE emp (id INT, name VARCHAR(20)); CREATE TABLE dept (id INT, name VARCHAR(20));Run:
CREATE TABLE report AS SELECT * FROM emp JOIN dept ON dept.id = emp.id;
You get: Duplicate column name 'id'(11.8.9)
Verified fixes
List the columns and alias the clashing ones
CREATE TABLE report AS SELECT emp.id AS emp_id, emp.name AS emp_name, dept.id AS dept_id, dept.name AS dept_name FROM emp JOIN dept ON dept.id = emp.id; SELECT COUNT(*) FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'report';
Tested on
| Step | MySQL | MariaDB | |||||||
|---|---|---|---|---|---|---|---|---|---|
| 5.6 | 5.7 | 8.0 | 8.4 | 9 | 10.6 | 10.11 | 11.4 | 11.8 | |
| CREATE TABLE ... AS SELECT from a join where both tables have an id column repro | ✓ 1060 | ✓ 1060 | ✓ 1060 | ✓ 1060 | ✓ 1060 | ✓ 1060 | ✓ 1060 | ✓ 1060 | ✓ 1060 |
| ALTER TABLE ADD a column that is already there version check | ✓ 1060 | ✓ 1060 | ✓ 1060 | ✓ 1060 | ✓ 1060 | ✓ 1060 | ✓ 1060 | ✓ 1060 | ✓ 1060 |
| List the columns and alias the clashing ones fix | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
CREATE TABLE ... AS SELECT from a join where both tables have an id column repro
MySQL 5.6✓ 10605.7✓ 10608.0✓ 10608.4✓ 10609✓ 1060
MariaDB 10.6✓ 106010.11✓ 106011.4✓ 106011.8✓ 1060
ALTER TABLE ADD a column that is already there version check
MySQL 5.6✓ 10605.7✓ 10608.0✓ 10608.4✓ 10609✓ 1060
MariaDB 10.6✓ 106010.11✓ 106011.4✓ 106011.8✓ 1060
List the columns and alias the clashing ones fix
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
✓works ✓ 1062fails with the error the step demonstrates ⚠works with a warning ≠runs, result differs ✗fails Tested 2026-11-25 on 5.6.51, 5.7.44, 8.0.46, 8.4.13, 9.7.4, 10.6.28, 10.11.19, 11.4.13, 11.8.9