Reputation: 403
I have table view in which I want to select last 10 records added in query. I am using following query which return all the records but I want last 10 added.
here is the query
NSString* select = [[NSString alloc] initWithFormat:@"select * FROM ContentMaster where ContentAddedByUserID='%@' AND 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.
I want to fetch all data which is last 10 added.
Upvotes: 6
Views: 10118
Reputation: 6276
According to documentation, each row in the Sqlite contains a 64 Bit auto incremented id associated with it.
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
.Upvotes: 4