My query looks like this:
INSERT INTO table1 (lfd, somedata)
select (select max(lfd) + 1 from table1), somedata from table2
Table 2 has several rows. So I want some rows to be inserted into table1. This works, but lfd is set to the same number for all inserted lines.
So, if max (ldf) + 1 is “2” for the first row inserted, it is also “2” for all next lines. This is not true because max (lfd) + 1 for the next line should return "3", of course.
How to tell mysql to re-evaluate a subquery for each insert?
I cannot touch table structures because I am transferring data from one php gallery to another another php gallery. The table structure is under application control.
In Oracle, I would just define the sequence and highlight squeencename.nextval in the subquery. - I'm sure this will work, but mysql does not offer a sequence, as far as I know, right?
source
share