Swap Insert for Update When Key Exists
Posted on April 30th, 2008 by Greg Allard in MySQL | Comments
When synchronizing tables or databases, sometimes it is useful to have a way to update a row if there is already an entry for a key. Using the MySQL syntax, ON DUPLICATE KEY UPDATE, it is possible to insert a row if it doesn’t exist or update it if there is already a row with that key.