List:General Discussion« Previous MessageNext Message »
From:Thimble Smith Date:September 14 1999 11:57pm
Subject:Re: INSERT INTO SELECT FROM same table
View as plain text  
At 17:51, 19990914, Mr. Anthony R.J. Ball wrote:
>  Sorry... I found this in the docs now... doesn't mean I like it... sigh.
>
>> I am trying to basically select MAX(order_number) + 1 from the table I
>> am in on the insert.  

Yep.  Either use an AUTO_INCREMENT column (this is exactly the kind of
thing AUTO_INCREMENT is for, probably), or if you can't do that, then
do something like:

    LOCK TABLES foo WRITE;
    SELECT MAX(order_number)+1 FROM foo;        /* store in <next_order> */
    INSERT INTO foo (order_number, etc) VALUES (<next_order>, 'bar');
    UNLOCK TABLES;

Tim
Thread
INSERT INTO SELECT FROM same tableMr. Anthony R.J. Ball15 Sep
  • Re: INSERT INTO SELECT FROM same tableMr. Anthony R.J. Ball15 Sep
    • Re: INSERT INTO SELECT FROM same tableThimble Smith15 Sep