Page 1 of 1

INSERT if UPDATE's WHERE clause returns 0

Posted: Thu Jul 28, 2005 12:19 pm
by anjanesh
I have

Code: Select all

UPDATE `table1` SET `field1` = 'a' WHERE `ID` = '123'
If 123 doesnt exist then create (INSERT) it.
Is there a way to do this in one SQL statement in MySQL ?

Thanks

Posted: Thu Jul 28, 2005 4:27 pm
by sulen
It is possible ...........but you need to use stored procedures for that ........ you might want to look at stored procedures for mysql

Posted: Thu Jul 28, 2005 5:46 pm
by timvw
Although it seems the other way round, it does what you want ;)

http://dev.mysql.com/doc/mysql/en/replace.html