zaka rehman zaka rehman - 1 year ago 79
SQL Question

How to update multiple fields at once in mysql

Hello i am building a school management system and i want to promote all the students with one click to the next class. I want whenever i press auto promote button then it updates database with next class for example

update students
set class=2
where class=1 and
set class=3
where class=2 and
set class=4
where class=3


Answer Source

you can do it with a single command

update students 
set class = class +1 
where class in (1,2,3);