我使用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];
任何想法如何解决此问题,以便或操作员
答案 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= '%@'