0

I have column named settings (type: tinyint unsigned not null).

That contains user settings in bits (0/1).

For example when i want update setting_1 then i do:

UPDATE `users` SET `settings`=`settings`|1

(That sets setting1 to 1 (true) ).

But, how i can do multiple update one column? For example:

UPDATE `users`
SET
 `settings`=`settings`|1,
 `settings`=`settings`&~2,
 `settings`=`settings`|4
WHERE `user`='xyz';

Any links that explain it?

1 Answer 1

2

You can perform all the operations together, e.g.

update user 
set settings = settings|1&~2|4;

You can also use brackets to limit the scope. Here is the SQL Fiddle for same.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.