How to Insert on Duplicate Key Update (an upsert)

This example of a upsert, an on duplicate key insert statement in MySQL. What it does is if the table zipcode_population has a unique index on the column zipcode a typical insert would error if a row the zipcode value of 98275 existed in the table. So you can do what is commonly called an upsert to update if the key is exists, insert otherwise.

INSERT INTO zipcode_population (zipcode,population,number_of_houses) VALUES (98275,72121,30123)
ON DUPLICATE KEY UPDATE population=72121, number_of_houses = 30123;