[英]how to get last 10 added records in sqlite table in iphone
I have table view in which I want to select last 10 records added in query. 我有一个表视图,我想选择查询中添加的最后10条记录。 I am using following query which return all the records but I want last 10 added.
我正在使用以下查询,该查询返回所有记录,但我想添加最后10个。
here is the query 这是查询
NSString* select = [[NSString alloc] initWithFormat:@"select * FROM ContentMaster where ContentAddedByUserID='%@' AND HiveletCode='%@'",appDelegate.userID,appDelegate.organizationCode];
NSString * select = [[NSString alloc] initWithFormat:@“ select * FROM ContentMaster,其中ContentAddedByUserID ='%@'和HiveletCode ='%@'”,appDelegate.userID,appDelegate.organizationCode];
I have searched some where that we can get by top records like this I get that we can fetch using date between two dates any idea how to get without date last 10 records. 我已经搜索了一些我们可以从顶级记录中获取的信息,例如,我可以使用两个日期之间的日期获取任何想法,无论如何获取没有日期的最近10条记录。
I want to fetch all data which is last 10 added. 我想获取最近添加的所有数据。
According to documentation , each row in the Sqlite contains a 64 Bit auto incremented id associated with it. 根据文档 ,Sqlite中的每一行都包含一个与之关联的64位自动递增ID。
So you can use query as 因此,您可以将查询用作
SELECT * FROM ContentMaster WHERE ContentAddedByUserID='%@' AND HiveletCode='%@'
ORDER BY ROWID DESC
LIMIT 10
Remember, 记得,
ROWID, _ROWID_, or OID
, then the use of that name will refer to the declared column not to the internal ROWID
. ROWID, _ROWID_, or OID
,则使用该名称将引用已声明的列而不是内部ROWID
。 ROWID
. ROWID
的别名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.