如何在sqlite iphone中使用带有ORDER BY的where子句

时间:2013-11-05 06:33:04

标签: ios iphone sqlite

我有一个表,我希望它应该通过desc视图获取数据,但是在这里使用的cluase是查询它不会返回任何东西。

                 select = [[NSString alloc] initWithFormat:@"select * FROM ContentMaster WHERE ContentTagText ORDER BY Views DESC ='%@'",appDelegate.tagInput];

如果删除where子句,则它以desc。

显示数据

1 个答案:

答案 0 :(得分:1)

你需要重构你的查询,你混淆了ORDER BY和WHERE子句。看起来应该是这样的:

NSString *select = [NSString stringWithFormat:@"SELECT * FROM ContentMaster WHERE ContentTagText = '%@' ORDER BY Views", appDelegate.tagInput];

我不知道列的确切名称,因此您可能需要对其进行调整。但基本上过滤器(='%@')需要在WHERE子句中,ORDER BY子句包含用于对结果进行排序的列。