Karbust
Karbust

Reputation: 67

1093 - You can't specify target table 'is_items' for update in FROM clause

I'm trying to set the values of the column 'id' by order, but my query isn't working:

UPDATE is_items SET id=(SELECT max(id)+1 FROM is_items WHERE id<160)

Error:

[Err] 1093 - You can't specify target table 'is_items' for update in FROM clause

I saw other asks about the same problem, but I can't understand very well the solution...

Thanks in advance,

King Regards

Upvotes: 0

Views: 255

Answers (1)

Bohemian
Bohemian

Reputation: 425398

You could do it in two steps by using a user defined variable:

set @id := (SELECT max(id)+1 FROM is_items WHERE id<160);
UPDATE is_items SET id=@id;

Upvotes: 0

Related Questions