开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜