相同的结果我试图将数据插入到两个表,其中表2没有主键,但只有外国的:选择最后一个ID返回多个请求
insert into table1 ....;
insert into table2 (a, column2, c) values(1, (select id from table1 order by inserted_at desc limit 1), 33);
insert into table1 ....;
insert into table2 (a, column2, c) values(1, (select id from table1 order by inserted_at desc limit 1), 33);
insert into table1 ....;
insert into table2 (a, column2, c) values(1, (select id from table1 order by inserted_at desc limit 1), 33);
和我结束了同一个ID中所有3个请求中的table2
为column2
。为什么以及我该如何修复?
你确定你在所有3次迭代中都不在'table1'中插入类似的数据?很难理解,除非你提供了'table1'的精确插入语句,并解释了如何使用'inserted_at'。我猜你在插入sysdate,但没有插入语句,我们只能猜测。 – Utsav
使用串行列。不要自己计算ID - 数据库会为你做这件事。 –
@戈登林诺夫,我没有。 – Johshi