表mysql的倒​​数第二行 [英] second last row of a table mysql

查看:135
本文介绍了表mysql的倒​​数第二行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个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不能保证指向实际记录.试试:

LAST_INSERT_ID()-1 has no guarantee of pointing at an actual record. Try:

SELECT * FROM table ORDER BY id DESC LIMIT 1,1

理想情况下,您应该使用id以外的其他方法来确定记录的期限,最好是时间戳记.

Ideally you should be using something other than id to determine the age of a record, preferably a timestamp.

这篇关于表mysql的倒​​数第二行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆