I've got a 'jobs' table where each row has a 'worker_id' that is either zero (job is not being worked on) or some unique ID that needs to be incremental.
Basically, when assigning this worker_id, I want to give it the first next available worker_id.
Here's what I'm trying:
UPDATE jobs SET worker_id=(SELECT MAX(worker_id)+1 FROM jobs) WHERE jobname='Abc'
The idea behind this is: if the current highest worker_id in my jobs table is 14, this query would set the worker_id for my job 'Abc' to 15.
But instead, this results in an error:
#1093 - You can't specify target table 'jobs' for update in FROM clause
What should I do?
FYI, the output of SHOW CREATE TABLE jobs is:
CREATE TABLE jobs (
jobname varchar(200) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
worker_id int(11) NOT NULL DEFAULT '0',
email varchar(200) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
customer_id int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
(I just removed the ` chars around table and column names for pasting as code here on StackExchange)