Although you can do this via straight_join, you can also explicitly get locks on the rows you want, duplicating the selection ... to update on the one you want to get first.
CREATE TEMPORARY TABLE colorsToUpdate ( colorID BIGINT(20) NOT NULL, modelID BIGINT(20) NOT NULL ); insert into colorsToUpdate ( colorID, modelID) SELECT id, model_id FROM colors where id in (101, 105, 106);
Since locking is performed in several stages, it would be possible to change the elements in the "colors" table between setting up a temporary table and completing locking of two tables.
This may be good for you (i.e. if you want to modify existing records when you start a transaction), but it can cause subtle errors if that is not what you want.
Danack
source share