ERROR 1060 occurs when a CREATE TABLE, ALTER TABLE, or SELECT statement tries to define the same column name twice. Resolve this by identifying the duplicate column and either removing, renaming, or qualifying it uniquely.
MySQL Error 1060 (ER_DUP_FIELDNAME) is thrown when you attempt to create or modify a table with duplicate column names. The MySQL server validates column identifiers during DDL (Data Definition Language) execution and rejects any statement that repeats a column name within the same table or result set. This is a strict validation rule because relational databases require each column within a table to have a unique identifier.
First, check your SQL statement or database schema to find the duplicate column reference. Look at the error message carefully—it usually specifies which column name is duplicated.
-- Example: This CREATE TABLE will fail
CREATE TABLE users (
id INT PRIMARY KEY,
email VARCHAR(255),
email VARCHAR(100) -- DUPLICATE!
);
-- ERROR 1060: Duplicate column name 'email'For existing tables, use DESCRIBE or SHOW CREATE TABLE to inspect the current structure:
DESCRIBE users;
SHOW CREATE TABLE users\GIf you're using ALTER TABLE to add a column, first verify that the column doesn't already exist:
-- View all columns in the table
SHOW COLUMNS FROM users;
-- Or use information schema
SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'users' AND TABLE_SCHEMA = 'your_database';If the column already exists and you don't need it, drop it first:
ALTER TABLE users DROP COLUMN old_column_name;Remove or rename the duplicate column in your CREATE TABLE statement:
-- WRONG: Duplicate email column
CREATE TABLE users (
id INT PRIMARY KEY,
email VARCHAR(255),
email VARCHAR(100)
);
-- CORRECT: Rename the second one or remove it
CREATE TABLE users (
id INT PRIMARY KEY,
email VARCHAR(255),
email_backup VARCHAR(100) -- Renamed to be unique
);When creating a view or selecting into a new table, use column aliases to ensure all column names are unique:
-- WRONG: Both tables have 'name' column, creates duplicate
CREATE VIEW user_profile AS
SELECT users.name, profiles.name
FROM users
JOIN profiles ON users.id = profiles.user_id;
-- ERROR 1060: Duplicate column name 'name'
-- CORRECT: Use aliases to distinguish columns
CREATE VIEW user_profile AS
SELECT users.name AS user_name, profiles.name AS profile_name
FROM users
JOIN profiles ON users.id = profiles.user_id;To make your ALTER TABLE statements idempotent and avoid duplicate column errors in migrations, use IF NOT EXISTS:
-- MySQL 8.0+: Safely add column only if it doesn't exist
ALTER TABLE users ADD COLUMN last_login TIMESTAMP NULL IF NOT EXISTS;For older MySQL versions, check first:
-- Check if column exists before adding
ALTER TABLE users
ADD COLUMN last_login TIMESTAMP NULL;
-- Will fail if it already exists; wrap in application logic to skip if neededAfter correcting your SQL, verify the table structure and re-execute the statement:
-- Verify no duplicates
DESCRIBE users;
-- Re-run your original statement
CREATE TABLE users (
id INT PRIMARY KEY,
email VARCHAR(255),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Or re-run your ALTER
ALTER TABLE users ADD COLUMN phone VARCHAR(20);Because the invalid statement fails before any changes are applied, simply fix and rerun—no rollback is needed.
Case Sensitivity: On Unix systems with lower_case_table_names=0, column names are case-sensitive (Name and name are different). On Windows and case-insensitive systems, they collide and trigger error 1060. Check your MySQL configuration: SHOW VARIABLES LIKE 'lower_case_table_names';
ORM Migration Tools: If you're using Prisma, Sequelize, TypeORM, or Alembic, ensure your migration files don't contain duplicate column definitions. Some tools generate migrations incorrectly when schema models have duplicates. Review generated migrations before running them.
Transaction Safety: DDL statements like CREATE TABLE and ALTER TABLE are not fully transactional in all storage engines, but the statement-level atomicity means that failed operations won't partially apply changes to the table structure.
ERROR 1064: You have an error in your SQL syntax
How to fix "ERROR 1064: You have an error in your SQL syntax" in MySQL
ERROR 1054: Unknown column in field list
Unknown column in field list
ER_WINDOW_RANGE_FRAME_NUMERIC_TYPE (3589): RANGE frame requires numeric ORDER BY expression
RANGE frame requires numeric ORDER BY expression in MySQL window functions
CR_ALREADY_CONNECTED (2058): Handle already connected
How to fix "CR_ALREADY_CONNECTED (2058): Handle already connected" in MySQL
ER_WINDOW_DUPLICATE_NAME (3591): Duplicate window name
How to fix ER_WINDOW_DUPLICATE_NAME (3591) in MySQL window functions