我使用这段代码来搜索A列。如果我想同时搜索A列和B列,我应该做什么修改?
String sql = "SELECT * FROM " + TABLE_NAME +
" WHERE " + ColumnA + " LIKE ? ORDER BY " + ColumnA + " LIMIT 100";
我试过了,但没用:
String sql = "SELECT * FROM " + TABLE_NAME +
" WHERE " + ColumnA + " LIKE ? ORDER BY " + ColumnA + " LIMIT 100 OR SELECT * FROM " + TABLE_NAME +
" WHERE " + ColumnB + " LIKE ? ORDER BY " + ColumnB + " LIMIT 100";
我做错什么了吗?
4条答案
按热度按时间mxg2im7a1#
您可以使用OR连接两个表达式。但是,两个表达式都必须是完整的表达式:
dluptydi2#
是否要查找UNION而不是OR?http://www.tutorialspoint.com/sqlite/sqlite_unions_clause.htm
baubqpgj3#
进行两个不同的查询。并通过
union
关键字合并结果。fzsnzjdm4#
致OP:
在您的答案中,过滤必须是每个字段的
OR
分别针对LIKE ?
。因此,该行应为
String sql = "SELECT * FROM " + TABLE_NAME + " WHERE ( " + ColumnA + " LIKE ?) OR (" + ColumnB + " LIKE ?) ORDER BY " + ColumnA + " LIMIT 100";