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;
You can also write this query.
UPDATE User SET status = IF(status = 0, 1, 0);