UPDATE `table`
SET `onWork` = 1, `timestamp` = NOW()
WHERE `onWork` = 0 AND (@id := `id`) > 0
ORDER BY `timestamp`
LIMIT 1
SELECT *
FROM `table`
WHERE `id` = @id
UPDATE `table`
SET `onWork` = 0, `timestamp` = NOW(), ...
WHERE `id` = @id
SET @id := 0;
UPDATE `mail`
SET `status` = `sending`
WHERE (@id := `id`) AND `status` = 'awaits'
ORDER BY `id`
LIMIT 1;
SELECT * FROM `mail` WHERE `id` = @id;