I have a table
id mid userid remarks
1 2 8 7
2 2 8 6
3 2 8
for mysql Node.js developers especially
I was unable to get direct-value in mysql-driver for node.js i.e. when I run the following query
SELECT MAX(id) FROM Users
and I got the result as [RowDataPacket { MAX(id): 1 }]
I tried to retrieve the value from object console.log(MAX(id))
, but I couldn't
so I set an alias
i.e. maxid
SELECT MAX(id) as maxid FROM Users
and got it as [RowDataPacket { maxid: 1 }]
Which I can retrieve as console.log(maxid)
Try this:
SELECT MAX(id),mid,userid,remarks
FROM sample WHERE id NOT IN (
SELECT MAX(id) FROM sample
)
GROUP BY mid,userid,remarks
EDIT
See if this works
SQL FIDDLE DEMO
Select Id,mid,userid,remarks from sample Where id<(select max(Id) from sample)
order by id desc limit 1
Or
Select Id,mid,userid,remarks from sample
order by id desc limit 1 offset 1