MySQL INSERT ON DUPLICATE KEY UPDATE

This tutorial shows you how to use MySQL INSERT ON DUPLICATE KEY UPDATE statement to update data if the duplicate UNIQUE index or PRIMARY KEY occurs.