Comment

AP: Steve Jobs Resigning from Apple

130
Charles Johnson8/24/2011 5:39:06 pm PDT

I’d just like to say how much I love the MYSQL query “INSERT INTO … ON DUPLICATE KEY UPDATE”.

If you don’t know what I’m talking about don’t worry about it. But this query is the cat’s PJs. Solved a problem I’ve been wrestling with for months.

If the table has a unique index, and you want to insert a row with a duplicate value in that indexed column, it falls through to the “ON DUPLICATE KEY UPDATE” clause, without the need for two queries (one to check for the duplicate key, one to insert/update). An elegant way to handle a common problem.