Android的SQLite的查询 - 获取最新的10条记录 [英] Android SQLite Query - Getting latest 10 records

查看:4043
本文介绍了Android的SQLite的查询 - 获取最新的10条记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于 SQL 查询的一个问题。 我已经保存在我的Andr​​oid应用程序的数据库。我只是想找回插入到数据库的最后10条消息。

I have a problem regarding SQL Query. I have a database saved in my android application. I just want to retrieve the last 10 messages inserted into the DB.

当我使用:

Select * from tblmessage DESC limit 10;

是的,它给我的10条消息,但是从 TOP 。但我想在最后一个 10的消息。是否有可能?

Yes it gives me the 10 messages but from the TOP. But I want the LAST 10 messages. Is it possible??

假设整个表的数据是 - 1,2,3,4,5 .... 30 我写查询语句select *从tblmessage其中timestamp递减限制10 它显示了30,29,28 ...... 21 但我想的序列 - 21,22,23 ...... 30

suppose the whole table data is - 1,2,3,4,5....30 I wrote query select * from tblmessage where timestamp desc limit 10 It shows 30,29,28...21 But I want the sequence as - 21,22,23...30

我怎么能得到同样的

感谢

推荐答案

在DESC更改为ASC,你会得到你想要的记录,但如果你需要他们订购的,那么你将需要扭转他们来的顺序在你可以做,在你自己的code或简单地扩展您的查询像这样:

Change the DESC to ASC and you will get the records that you want, but if you need them ordered, then you will need to reverse the order that they come in. You can either do that in your own code or simply extend your query like so:

select * from (select * from tblmessage order by sortfield ASC limit 10) order by sortfield DESC;

您真的应该总是by子句指定的顺序,而不仅仅是ASC或DESC。

You really should always specify an order by clause, not just ASC or DESC.

这篇关于Android的SQLite的查询 - 获取最新的10条记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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