【发布时间】:2013-08-07 06:26:33
【问题描述】:
Mysql 表
create table table1(
id int(3) zerofill auto_increment primary key,
username varchar(10)
)
engine=innodb;
Mysql 插入查询
insert into table1 (username)
select id from (select id from table1) as a where
a.id=last_insert_id();
我试图通过从同一个表和同一行中选择最后一个 id 来插入一个表,上面的查询解释了我想要做什么。插入查询在 id 和用户名中都给出了 null 值. 预期结果如下。
id username
001 001
002 002
003 003
【问题讨论】:
-
stackoverflow.com/questions/292851/…此链接可能对您有所帮助
-
你为什么要这样做:
select id from (select id from table1) as a where a.id=last_insert_id()?
标签: mysql