如何从mysql数据库中获取倒数第二行? [英] How to get second last row from a mysql database?

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

问题描述

我刚刚进行了查询以从数据库中获取倒数第二行:

I just made a query to get second last row from database:

这是代码:

SELECT TOP 1 * FROM
   (select Top 2 * from Categories ORDER BY CategoryID DESC)x                     
   ORDER BY CategoryID

但是这段代码在新版本中给了我错误的语法错误.

but this code gives me error syntax error in new version.

在旧版本中,此代码工作正常.

In older version this code work fine.

有什么问题:我在表中有 10 个结果,当我提交这个查询时,它给了我 9 行.但是当从表中删除 9 行时,现在我有 8 和 10.但是这段代码给了我 10.

What is problem: I have 10 results in the table, and when I submit this query, it gives me 9 row. But when 9 row delete from table, now I have 8 and 10. But this code gives me 10.

推荐答案

SELECT * FROM Categories ORDER BY CategoryID  DESC LIMIT 1,1

这篇关于如何从mysql数据库中获取倒数第二行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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