Mysql to update status 1->0 and vice versa using single query

Question >>
I have a table name 'User' which have 3 fields.
> Fields name are below.
       1] id
       2] name
       3] status
> Table have four recored which are listed below.
- id    name    status -
  1      A           0
  2      B           0
  3      C           1
  4      D           1

I want to update status 0 to 1 and 1 to 0 through single sql query.

Answer >>
UPDATE User SET status = !status;
About these ads

One thought on “Mysql to update status 1->0 and vice versa using single query

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s