INSERT OR UPDATE + MYSQL

Insert if not there, update on duplicate.


Query: INSERT INTO TABLE_NAME (COLUMN_NAME1, COLUMN_NAME2) VALUES (?, ?) ON DUPLICATE KEY UPDATE COLUMN_NAME1=VALUES(COLUMN_NAME1), COLUMN_NAME2=VALUES(COLUMN_NAME1) + 2;


And the key means the, unique key. It is advised not to use the "on duplicate key update", when there are 2 or more number of unique keys (primary key is also a unique key) present in a table.