当有多个需要满足的条件时,如何查询sqlite

时间:2013-06-19 14:41:13

标签: android sqlite where-clause

我正在使用内容提供程序,需要查询一个表,其中row = thing1的一列和同一行的另一列= thing2。 我知道你可以查询一个表只有一个条件,如:

Cursor c = contentResolver.query(content_uri, projection, variable + "='" + thing1 + "'", null, null);

现在我如何查询两个条件?任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:5)

这应该有效:

Cursor c = contentResolver.query(content_uri, projection, "col1=? AND col2=?", args, null);

其中argsString[]值,可替换查询中的?

答案 1 :(得分:0)

试试这个

Cursor c = contentResolver.query(content_uri, projection, variable + "='" + thing1 + "' AND "+variable2 + "='"+thing2+"'"  ,  null, null);