mysql - Change enum column automatically -
i have column named status in table of enum type , can have 2 values either 1 or 0. want write query automatically check current value of enum , change other value.
for example, have rows in table:
id | name | status -----+---------+--------- 1 | abc | 0 -----+---------+--------- 2 | xyz | 1 now want write mysql query pass id of row update , automatically check current status , change other. example, if pass id=1 automatically check current value of status column , change 1. similarly, if pass id=2 checks status value of row 2 , changes 0.
here $id passed id. note, while bool operations (like status=!status) "nifty", it's not work enum-s such way.
update t set status=if(status='0', '1', '0') id=$id also, idea change type tinyint if it's storing 0 , 1 (then status=!status idea use)
Comments
Post a Comment