Now that’s something I did not know: one can perform an insert, but if you specify ON DUPLICATE KEY UPDATE
(available since MySQL 4.1.0) in your query, the row will get updated … now that basically combines two queries in one (a SELECT
and then an INSERT
or UPDATE
depending on the number of rows returned from the SELECT
)! REPLACE INTO
apparently also does the trick (supports Primary Keys, not just Uniques). Thanks for the hat tip Ryan!