Allex Allex - 7 months ago 14
SQL Question

PHP mysql update multiple row by single query SET='101' where id =1,2,3,7,9

I am trying to update rows in mysql but I have to use for loop for multiple update for single value mysql query is

update table set column1='100' where id =1
update table set column1='100' where id =6
update table set column1='100' where id =14


I am using for loop for running query multiple times with different id, I want to run single query for update all rows. Is that possible?

i want to do something like that

update table set column1='100' where id=1,6,14;

Answer

Use IN() Operator

update table_name SET field_name='101'
where id IN(1,2,7,9) 
Comments