Insert a row or update it when a unique key already exists.
Section: insert, update, and delete
Upsert with ON DUPLICATE KEY UPDATE
sql
sql
INSERT INTO users (email, full_name)
VALUES ('ava@example.com', 'Ava Stone')
ON DUPLICATE KEY UPDATE full_name = VALUES(full_name);Explanation
A classic MySQL upsert pattern for unique-keyed rows.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing insert, update, and delete
Replace a row using REPLACE
Insert or delete-and-insert based on unique key conflicts.
Truncate a table
Remove all rows quickly and reset auto-increment counters.