OR运算符不在查询sqlite iphone中工作

时间:2013-11-19 07:55:24

标签: iphone sql sqlite

我使用Join运算符检查表中的两个值,但它不起作用

select = [[NSString alloc] initWithFormat:@"select * FROM ContentMaster LEFT JOIN  Category  ON  ContentMaster.CategoryID= Category.CategoryID where ContentMaster.ContentTitle='%@' || ContentMaster.ContentTagText='%@' ",appDelegate.tagInput,appDelegate.tagInput];

如果我不使用运算符并在where子句中使用它,那么它会显示结果。

select = [[NSString alloc] initWithFormat:@"select * FROM ContentMaster LEFT JOIN  Category  ON  ContentMaster.CategoryID= Category.CategoryID where ContentMaster.ContentTitle='%@'",appDelegate.tagInput];


select = [[NSString alloc] initWithFormat:@"select * FROM ContentMaster LEFT JOIN  Category  ON  ContentMaster.CategoryID= Category.CategoryID where ContentMaster.ContentTagText='%@'",appDelegate.tagInput];

任何想法如何解决此问题,以便或操作员

2 个答案:

答案 0 :(得分:2)

在SQL(特别是SQLite)中,运算符||通常表示字符串连接。

如果您需要逻辑or,请使用运算符OR

答案 1 :(得分:0)

sqlite中,只需使用or进行逻辑or操作:

SELECT * 
FROM ContentMaster 
LEFT JOIN  Category ON ContentMaster.CategoryID = Category.CategoryID 
WHERE ContentMaster.ContentTitle = '%@' OR ContentMaster.ContentTagText= '%@'