Reversing column values in mysql command line

Posted by user94154 on Stack Overflow See other posts from Stack Overflow or by user94154
Published on 2010-03-28T20:37:20Z Indexed on 2010/03/28 20:43 UTC
Read the original article Hit count: 255

Filed under:
|
|

I have a table posts with the column published, which is either 0 (unpublished) or 1 (published). Say I want to make all the published posts into unpublished posts and all the unpublished posts into published posts. I know that running

UPDATE posts SET published = 1 WHERE published = 0;
UPDATE posts SET published = 0 WHERE published = 1;

will end up turning all my posts into published posts. How can I run these queries in the mysql command line so that it truly "reverse" the values, as opposed to the mistake outlined above?

Thanks

© Stack Overflow or respective owner

Related posts about mysql

Related posts about update