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