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

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -