开发者

Cleaner way of manually updating multiple rows

开发者 https://www.devze.com 2022-12-24 02:25 出处:网络
I wanted to see if there is a cleaner and more effective way of writing the SQL statement below. (MySQL)

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)
0

精彩评论

暂无评论...
验证码 换一张
取 消