Is there a way to accomplish a single table scan in MySQL with an UPDATE? The following is a standard example:
IF EXISTS (SELECT * FROM Table1 WHERE Column1='SomeValue')
UPDATE Table1 SET (...) WHERE Column1='SomeValue'
ELSE
INSERT INTO Table1 VALUES (...)
This is the ideal situation I’d like to happen in MySQL (But this is MsSQL):
UPDATE user SET (name = 'jesse') WHERE userid ='10001'
IF @@ROWCOUNT=0
INSERT INTO user (name) VALUES('jeeeeee')
It’s sort of reversed in MySQL. You perform the insert, and if the key already exists, then update the row:
This is predicated on you having a unique key for the table (which you do, right?)