mysqldude
Error codes › 1060

MySQL & MariaDB error 1060: Duplicate column name

Error messageDuplicate 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.

MySQLMariaDB
SymbolER_DUP_FIELDNAMEER_DUP_FIELDNAME
SQLSTATE42S2142S21
TypeServer errorServer error
Versionsevery release since 5.0 activeevery 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 … (or CREATE VIEW over the same) when both tables have id or name. A plain SELECT * over the join is fine because result sets may repeat names; a table can’t.
  • ALTER TABLE … ADD COLUMN in a migration that already ran.
  • A derived table such as SELECT * FROM (SELECT a.id, b.id FROM a JOIN b …) x repeats 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 has ADD 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.

  1. Connect with mysql -u root -p and 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));
  2. 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

  1. 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

StepMySQLMariaDB
5.65.78.08.4910.610.1111.411.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

Related errors

  • 1050 ER_TABLE_EXISTS_ERRORexplained
  • 1054 ER_BAD_FIELD_ERRORexplained
  • 1052 ER_NON_UNIQ_ERROR