我正在使用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')
Run Code Online (Sandbox Code Playgroud)
当我执行时select myID, last_insert_id() as NewID from maxID
,我得到如下输出
myId NewID
A001 0
A002 0
A004 0
A003 0
Run Code Online (Sandbox Code Playgroud)
当我尝试下面的代码,
select myId, last_insert_id() as NewID, @rowid:=@rowid+1 as myrow from maxID, (SELECT @rowid:=0) as init
我得到如下输出.
myId NewID rowid
A001 0 1
A002 0 2
A004 0 3
A003 0 4
Run Code Online (Sandbox Code Playgroud)
但是,当我使用代码时 …