Update same table with IF ELSE Condition in MySQL
I am trying to update the user_status filed with condition:
update pm_users
set user_status = if (
(select u.user_status from pm_users u where u.user_id = 3
) = '1', '0', '1' )
where user_id = 3
means if user_status = 1 then update the status with 0 and if user status
is 0 then with 1.
I am getting the error: You can't specify target table 'pm_users' for
update in FROM clause
I think it means i can't use this query like above for the same table? I
am not sure.
Please help me to move on the right way, and make me correct.
No comments:
Post a Comment