Thanks for the lead Jeff, maybe you can elaborate?
We need to essentially do this:
Insert into orders (number, comment) select max(number) + 1, 'comment' from
orders where user = 'user_name';
(Not supported in MySQL)
Another user suggested using a select first to get the value, then doing an
UPDATE sequence_table
SET sequence = LAST_INSERT_ID(sequence + 1)
Further calls to LAST_INSERT_ID on the same connection will return the value
"sequence + 1". It's connection specific, so multiple connections can update
your sequence table without interfering with each other.
There's a great exa
Hi!,
INSERT INTO ... SELECT statement works in MySQL. The web site is :
http://www.mysql.com/doc/I/N/INSERT_SELECT.html
I have no idea what you meant by "it doesn't work for the same tables"..
But as the answer to your question, you could do something like:
SELECT @a:=MAX(fieldname) FROM TABLE;
use an auto_increment column.
Or if this is during an "UPDATE"
UPDATE tbl SET col = col + 1 WHERE ..;
Allon Bendavid wrote:
>
> Hello All-
>
> I just read that an Insert ... Select naming the same table is not supported
> in MySQL.
>
> What is the alternative? What we need to do is simply