second last row of a table mysql
I was playing in a MySQL database and wanted to only view the record that had second to last of table but did not get any row the query is given below What is the problem of my query
SELECT * FROM table WHERE id='(LAST_INSERT_ID()-1)'
开发者_运维百科
LAST_INSERT_ID()-1
has no guarantee of pointing at an actual record. Try:
SELECT * FROM table ORDER BY id DESC LIMIT 1,1
Ideally you should be using something other than id to determine the age of a record, preferably a timestamp.
精彩评论