MySQL update with subquery 1

MySQL update with subquery

update Users set Valid = 0
where Id in (
  select Id from (
    select Id from Users where Id < 100
  ) as t

Here is what the above code is Doing:
1. Create a temporary table t with the Ids of the users to be deleted.
2. Delete the users with Ids in t.

The temporary table is necessary because you can't use a subquery in the where clause of a delete statement.

Similar Posts