What2107
What2107

Reputation: 33

how to query sqlite when there are more than one condition that needs to be met

I am using a content provider and need to query a table where one column of the row = thing1 and another column of that same row = thing2. i know you can query a table for just one condition like:

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

now how can i query for two conditions? any help would be appreciated.

Upvotes: 0

Views: 834

Answers (2)

CommonsWare
CommonsWare

Reputation: 1006584

This should work:

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

where args is a String[] of values to substitute in for the ? in the query.

Upvotes: 5

zozelfelfo
zozelfelfo

Reputation: 3776

Try this

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

Upvotes: 0

Related Questions