Is it possible in Mysql to turn this query into 1 query ?
UPDATE users SET users.title =1 WHERE users.oldId = 'adab01' LIMIT 1 ;
UPDATE users SET users.title =2 WHERE users.oldId = 'agok01' LIMIT 1 ;
UPDATE users SET users.title =1 WHERE users.oldId = 'alla01' LIMIT 1 ;
UPDATE users SET users.title =2 WHERE users.oldId = 'allm01' LIMIT 1 ;
Something similar to this in SELECT :
INSERT INTO users (first_name,last_name) VALUES("John", "Doe"),("Jane", "Doe")
Is this doable in MySql ?
Just so you know what i was trying to do :
I was reading this article , Jump to (Avoid doing SQL queries within a loop)
You’d need to use a
CASEstatement to do this, and it won’t be terribly pretty:Note that the
WHEREis optional, as without it the data shouldn’t be changed unnecessarily, but it will also “touch” every row in the table rather than only those that need updating.