I am using mysql and am encountering some problems. I want to get the last row inserted.
<<Below are the details →
The following is a way to create a table.
create table maxID (myID varchar(4))
I inserted four values into it as shown below
insert into maxID values ('A001')
insert into maxID values ('A002')
insert into maxID values ('A004')
insert into maxID values ('A003')
When I execute select myID, last_insert_id() as NewID from maxID, I get output as below
myId NewID
A001 0
A002 0
A004 0
A003 0
When I tried under the code,
select myId, last_insert_id() as NewID, @rowid:=@rowid+1 as myrow from maxID, (SELECT @rowid:=0) as init
I get the output as shown below.
myId NewID rowid
A001 0 1
A002 0 2
A004 0 3
A003 0 4
However, when I use the code select myId, last_insert_id() as NewID, @rowid:=@rowid+1 as myrow from maxID, (SELECT @rowid:=0) as init where @rowid = 4, I get an error likeUknown column 'myrow' in where clause
When I use where @rowid=4, I do not get any data in the tables.
Note: Here I use 4 to get the desired result. Later I can get this from the request(select max(rowid) from maxID)
, , , , .. A003.
.
Update:
, , .