Tag: last insert id

SELECT LAST_INSERT_ID()

有人可以解释MySQL函数LAST_INSERT_ID()的工作原理。 我想在数据库中获取最后一行插入的id,但每次都得到1。 我用mybatis。 示例查询是: INSERT INTO something (something) VALUES (#{something}) SELECT LAST_INSERT_ID() 码: System.out.println(“Id : ” + id) 输出: Id : 1

从mysql获取最后一条记录

我正在使用mysql并面临一些问题。 我想检索插入的最后一行。 <> 以下是我创建表格的方法。 create table maxID (myID varchar(4)) 我在其中插入了四个值,如下所示 insert into maxID values (‘A001’) insert into maxID values (‘A002’) insert into maxID values (‘A004’) insert into maxID values (‘A003’) 当我select myID, last_insert_id() as NewID from maxID执行select myID, last_insert_id() as NewID from maxID ,我得到如下输出 myId NewID A001 0 A002 0 A004 0 A003 0 当我尝试下面的代码, […]