views:

38

answers:

2

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. Optimize :)

+1  A: 

Make use of the IN clause

UPDATE login SET is_admin=1
WHERE
memberid IN (1,6,10,12,7,3)
Marek Karbarz
+4  A: 

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)
Pascal MARTIN
Thanks that worked fine! It is only for the purpose of looking better and making it easier to read.
WmasterJ
You're welcome :-) -- well, it's looking better ;-) *(Not sure about it, but maybe MySQL could make better use of indexes with IN than with multiple OR)*
Pascal MARTIN