List:General Discussion« Previous MessageNext Message »
From:Sherzod Ruzmetov Date:January 29 2003 11:15pm
Subject:RE: Increment in update
View as plain text  
    :+-------+--------------+------+-----+---------+----------------+
    :| Field   | Type           | Null  | Key | Default | Extra          |
    :+-------+--------------+------+-----+---------+----------------+
    :| id      | int(11)         |         | PRI | NULL    |
    :auto_increment |
    :| descr | varchar(255) | YES| MUL | NULL    |                     |
    :+-------+--------------+------+-----+---------+----------------+
    :
    :
    :mysql> update tb_roubr set id=id+1 where id>1 order by id;
    :ERROR 1064: You have an error in your SQL syntax near 'order
    :by id' at line 1
    :why this is not working and what are other ways to do such a query.

You are defeating the purpose of auto_increment with "id=id+1" expression.
Simply
pass it a NULL or nothing at all:

   UPDATE tb_roubr SET id=NULL WHERE id > 1;


Every time you pass "id" NULL value, mysql will *auto_increment* the value
of the column
automaticly so you never have to worry about it.

Sherzod


Thread
Increment in updateIgor Kutsyy29 Jan
  • Re: Increment in updateDan Nelson30 Jan
    • Re: Increment in updateChristian Kohlschütter30 Jan
      • Re: Increment in updateDan Nelson30 Jan
        • Re: Increment in updateChristian Kohlschuetter30 Jan
  • RE: Increment in updateSherzod Ruzmetov30 Jan