Cleaner way of manually updating multiple rows
I wanted to see if there is a cleaner and more effective way of writing the SQL statement below. (MySQL)
UPDATE login SET is_admin=1
WHERE
memberid = 1
OR
memberid = 6
OR
memberid = 10
OR
memberid = 12
OR
memberid = 7
OR
memberid = 3;
Simply want a nicer way of solving it. Opti开发者_开发技巧mize :)
Not sure it'll be faster or more optimized, but it'll be easier to read, using IN()
:
UPDATE login
SET is_admin=1
where memberid IN (1, 6, 10, 12, 7, 3)
Make use of the IN
clause
UPDATE login SET is_admin=1
WHERE
memberid IN (1,6,10,12,7,3)
精彩评论