Get MAX value in mysql query
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
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
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)