I have a table
id mid userid remarks 1 2 8 7 2 2 8 6 3 2 8 4 4 2 8 5 5 2 8 2 6 2 8 3 7 2 8 7 8 2 8 0 9 2 8 1 10 2 8 8
I need the last line of remark before this line. those. note '1'
SELECT MAX(id),mid,userid,remarks FROM sample
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 the following:
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 it works
SQL FIDDLE DEMO