Is it possible to do the following in 1 statement instead of 2. I need to set the isActive flag for one id and set all the others to false. Im using postgres DB.
tblNames
------------------------
id,name,isActive
1,'n1',true
2,'n2',false
3,'n3',false
4,'n4',false
update tblnames
set isActive = true
where id = 4
update tblnames
set isActive = false
where id != 4
Does that work?
update tblnames
set isActive = (id = 4)
In case it doesn't (I don't know Postgres syntax well enough), this will surely work:
update tblnames
set isActive case id when 4 then true else false end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With