I am trying to make update statement in MySql table – just migrating data from one user to second user. The concrete row should be migrated only when the row with same unique ID devid doesn’t exist yet for that second user.
The update statement that I used is:
update userdata as userdata1 set userid=${newuser}
where
userid=${olduser} and
userdata1.devid !=
(select devid from userdata as userdata2
where
userdata2.userid = ${newuser} and userdata2.`devid` = userdata1.`devid`)
The MySql returns:
You can't specify target table 'userdata' for update in FROM clause
But from the other way, similar select statement works, or similar update statement, when I test data on another that same table works as well. So that is this some limitation, that there is not possible to do select on same table during update? And how to manage this?
Thanks,
Jindrich
You can use a left join: