0

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

Karbust
  • 67
  • 2
  • 10
  • possible duplicate of [Mysql error 1093 - Can't specify target table for update in FROM clause](http://stackoverflow.com/questions/45494/mysql-error-1093-cant-specify-target-table-for-update-in-from-clause) – user700390 Apr 03 '15 at 00:20

1 Answers1

0

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;
Bohemian
  • 412,405
  • 93
  • 575
  • 722
  • @vince yes - that is what OP's query does. I just addressed the syntax problem (not any potential logic problems) – Bohemian Apr 03 '15 at 00:23