sql - Update all rows to 0 and only one to 1 -


how can update rows @ 0 , id=x set 1.

update car_ads  set deal_of_the_week_p = if(deal_of_the_week_p = 1, 0, 1)  ad_id = 999 

now have not working.

thanks

assuming using standards-compliant dbms, use

update car_ads set deal_of_the_week_p = case when ad_id = 999 1 else 0 end

alternatively, run 2 separate updates -

update car_ads set deal_of_the_week_p = 0 update car_ads set deal_of_the_week_p = 1 ad_id = 999


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -