MySQL 8.4Lab-verified · 2026-11-29

MySQL ERROR 1060 (42S21): Duplicate column name 'phone'

A table or view would end up with two columns of the same name.

MySQL 8.4.13
1060 (42S21): Duplicate column name 'phone'

Jump to a cause

  1. 01ALTER TABLE ... ADD COLUMN run a second time
  2. 02CREATE TABLE ... AS SELECT o.*, c.* from a join
  3. 03CREATE VIEW selecting the same column name from two tables

Lab-verifiedReproduced and fixed on MySQL 8.4.13 · 2026-11-29 · container image mysql:8.4

ERROR 1060 (42S21) means the result would have two columns with the same name. It happens when a migration adds a column that already exists, or when a join returns id or name from both tables and you save that result as a table or view.

3 cases reproduced on MySQL 8.4.

01ALTER TABLE ... ADD COLUMN run a second time

phone was already added, and the same migration ran again. MySQL 8.4 has no ADD COLUMN IF NOT EXISTS, so the second run fails.

Setup
Setuprun as lab_a
CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR(50));
ALTER TABLE users ADD COLUMN phone VARCHAR(20);
OUTPUT
Query OK, 0 rows affected (0.02 sec)

Query OK, 0 rows affected (0.02 sec)
Records: 0  Duplicates: 0  Warnings: 0
Reproducerun as lab_a
ALTER TABLE users ADD COLUMN phone VARCHAR(20);
✕ ERROR
ERROR 1060 (42S21): Duplicate column name 'phone'
Checkrun as lab_a
SELECT COLUMN_NAME, COLUMN_TYPE FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'users' ORDER BY ORDINAL_POSITION;
OUTPUT
+-------------+-------------+
| COLUMN_NAME | COLUMN_TYPE |
+-------------+-------------+
| id          | int         |
| name        | varchar(50) |
| phone       | varchar(20) |
+-------------+-------------+
3 rows in set (0.00 sec)

information_schema.COLUMNS shows phone varchar(20) is already there. To make the script safe to rerun, build the DDL only when the column is missing: SET @ddl = IF((SELECT COUNT(*) ... COLUMN_NAME = 'phone') = 0, 'ALTER TABLE ...', 'SELECT ...') then PREPARE / EXECUTE. Here it printed phone already exists instead of failing.

After the fixrun as lab_a
SET @ddl = IF((SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'users' AND COLUMN_NAME = 'phone') = 0,
  'ALTER TABLE users ADD COLUMN phone VARCHAR(20)',
  'SELECT ''phone already exists'' AS msg');
PREPARE stmt FROM @ddl;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
✓ SUCCESS
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)
Statement prepared

+----------------------+
| msg                  |
+----------------------+
| phone already exists |
+----------------------+
1 row in set (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

02CREATE TABLE ... AS SELECT o.*, c.* from a join

Both orders and customers have an id column. o.*, c.* returns two id columns, and a table cannot have that.

Setup
Setuprun as lab_a
CREATE TABLE customers (id INT PRIMARY KEY, name VARCHAR(50));
CREATE TABLE orders (id INT PRIMARY KEY, customer_id INT, amount INT);
INSERT INTO customers VALUES (1, 'kim');
INSERT INTO orders VALUES (10, 1, 5000);
OUTPUT
Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.02 sec)

Query OK, 1 row affected (0.00 sec)

Query OK, 1 row affected (0.00 sec)
Reproducerun as lab_a
CREATE TABLE order_backup AS
SELECT o.*, c.* FROM orders o JOIN customers c ON c.id = o.customer_id;
✕ ERROR
ERROR 1060 (42S21): Duplicate column name 'id'
Checkrun as lab_a
SELECT COLUMN_NAME, GROUP_CONCAT(TABLE_NAME ORDER BY TABLE_NAME) AS tables FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME IN ('orders', 'customers') GROUP BY COLUMN_NAME HAVING COUNT(*) > 1;
OUTPUT
+-------------+------------------+
| COLUMN_NAME | tables           |
+-------------+------------------+
| id          | customers,orders |
+-------------+------------------+
1 row in set (0.00 sec)

information_schema.COLUMNS shows id exists in both customers and orders. List the second table's columns with aliases: c.id AS cust_id, c.name AS customer_name. The backup table is created with id, customer_id, amount, cust_id, customer_name.

After the fixrun as lab_a
CREATE TABLE order_backup AS
SELECT o.*, c.id AS cust_id, c.name AS customer_name FROM orders o JOIN customers c ON c.id = o.customer_id;
SELECT * FROM order_backup;
✓ SUCCESS
Query OK, 1 row affected (0.02 sec)
Records: 1  Duplicates: 0  Warnings: 0

+----+-------------+--------+---------+---------------+
| id | customer_id | amount | cust_id | customer_name |
+----+-------------+--------+---------+---------------+
| 10 |           1 |   5000 |       1 | kim           |
+----+-------------+--------+---------+---------------+
1 row in set (0.00 sec)

03CREATE VIEW selecting the same column name from two tables

e.name and d.name both come out as name. The view definition fails with Duplicate column name 'name'.

Setup
Setuprun as lab_a
CREATE TABLE depts (id INT PRIMARY KEY, name VARCHAR(50));
CREATE TABLE emps (id INT PRIMARY KEY, dept_id INT, name VARCHAR(50));
INSERT INTO depts VALUES (1, 'sales');
INSERT INTO emps VALUES (100, 1, 'lee');
OUTPUT
Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.02 sec)

Query OK, 1 row affected (0.00 sec)

Query OK, 1 row affected (0.00 sec)
Reproducerun as lab_a
CREATE VIEW emp_dept AS
SELECT e.id, e.name, d.name FROM emps e JOIN depts d ON d.id = e.dept_id;
✕ ERROR
ERROR 1060 (42S21): Duplicate column name 'name'
Checkrun as lab_a
SELECT COLUMN_NAME, GROUP_CONCAT(TABLE_NAME ORDER BY TABLE_NAME) AS tables FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME IN ('emps', 'depts') GROUP BY COLUMN_NAME HAVING COUNT(*) > 1;
OUTPUT
+-------------+------------+
| COLUMN_NAME | tables     |
+-------------+------------+
| id          | depts,emps |
| name        | depts,emps |
+-------------+------------+
2 rows in set (0.00 sec)

information_schema.COLUMNS shows both id and name exist in depts and emps. Give the two name columns aliases (e.name AS emp_name, d.name AS dept_name). The view is created and returns 100 / lee / sales.

After the fixrun as lab_a
CREATE VIEW emp_dept AS
SELECT e.id, e.name AS emp_name, d.name AS dept_name FROM emps e JOIN depts d ON d.id = e.dept_id;
SELECT * FROM emp_dept;
✓ SUCCESS
Query OK, 0 rows affected (0.01 sec)

+-----+----------+-----------+
| id  | emp_name | dept_name |
+-----+----------+-----------+
| 100 | lee      | sales     |
+-----+----------+-----------+
1 row in set (0.00 sec)

FAQ

How do I fix MySQL error 1060 Duplicate column name?

Find which column appears twice. For ALTER TABLE, check information_schema.COLUMNS first. For CREATE TABLE AS or CREATE VIEW, alias the duplicate columns.

Does MySQL support ADD COLUMN IF NOT EXISTS?

Not in MySQL 8.4. Check information_schema.COLUMNS and run the ALTER with PREPARE / EXECUTE only when the column is missing.

How do I copy a joined result into a new table without error 1060?

Do not use o.*, c.* when both tables share column names like id. List the columns and alias the duplicates, for example c.id AS cust_id.

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary users created for the test, each with full rights on a database of the same name (its default database); root is the administrator. MySQL 8.4.13