检索最后插入的ID列表

时间:2014-06-25 13:03:32

标签: mysql

 insert into table1 (select * from table2); 

表2有10条记录。我想从已插入的table1中检索10个ID列表(即autoincreamnet)。

2 个答案:

答案 0 :(得分:1)

如果它们是自动递增的,那么您要选择10个最高数字。选择id并按id降序排序,然后限制为10.

答案 1 :(得分:0)

您需要使用desc和limit

   INSERT INTO table1 (SELECT * FROM table2 ORDER BY id DESC LIMIT 10)