Q:

MySQL InnoDB Global Var?

I want to execute this code:
The idea is to get the item with the lowest MID that has not been used (mutex = 0). To prevent other Threads of reading this line FOR UPDATE is used and UPDATE decreases mutex.
START TRANSACTION;
SELECT MID as m, sender, receiver, content FROM queue WHERE mutex = 0 ORDER BY MID ASC limit 1 FOR UPDATE; 
UPDATE queue set mutex = -1 WHERE MID = m;
COMMIT;

However m is only known when the SELECT line is executed. How do I access it in the next query, without breaking the query, which would stop the TRANSACTION ?
P.S.: I know that mutex is something else than the thing I am using it for.

A:

You could use a variable:
START TRANSACTION;
SELECT @m:=MID, sender, receiver, content FROM queue WHERE mutex = 0 ORDER BY MID ASC limit 1 FOR UPDATE; 
UPDATE queue set mutex = -1 WHERE MID = @m;
COMMIT;

