I would like to know if it is possible to use REPLACE
MySQL statement in an InnoDB table to see if the key in the table already exists, if it does then increment the value by certain number (for instance 50), else insert a new record with with a certain value (50). Something like this:
REPLACE INTO test(id, NumValue) VALUES (1, NumValue + 50)
This statement doesn't work. It inserts/updates to NULL
value. If there is a way to do this using REPLACE
statement what is the correct syntax? I know I could do it in couple steps, first using SELECT
statement to find out if the record already exists, if it does then do an UPDATE
, if it doesn't, then do an INSERT
. But I was hoping it could be achieved by using just one step, using REPLACE
. And also, I want to avoid using sub-queries.