Here's my current sqlite code:
Cursor c = sqlDatabase.rawQuery("select docid as _id, recipeID from " + TABLE_RECIPE_NAME +
" where " + KEY_ownerID + " = ? ", new String[] { ownerID});
It works fine, but when I tried adding multiple where to something like this:
Cursor c = sqlDatabase.rawQuery("select docid as _id, recipeID from " + TABLE_RECIPE_NAME +
" where " + KEY_ownerID + " = ?, " + KEY_partnerID + " = ?, " + KEY_advertiserID + " = ?, " + KEY_chefID + " = ?", new String[] { ownerID, partnerID, advertiserID, chefID });
It returns an error. So how do I deal with multiple ?
This example demonstrate about How to where Clause in Android sqlite. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml.
SQLite is an open source SQL database that stores data to a text file on a device. Android comes in with built in SQLite database implementation. SQLite supports all the relational database features. In order to access this database, you don't need to establish any kind of connections for it like JDBC, ODBC etc.
This was an introduction to writing SQLite queries and the basics of querying the database and how you can filter the returned data. You can now, write your own SQLite queries.
This will give you only three unique values for the department name column: SQLite Aggregates are built-in functions defined in SQLite that will group multiple values of multiple rows into one value. Here are the aggregates supported by SQLite: Returned the average for all the x values.
change query to:
Cursor c = sqlDatabase.rawQuery("select docid as _id, recipeID from " +
TABLE_RECIPE_NAME + " where " + KEY_ownerID + " = ? AND " + KEY_partnerID +
" = ? AND " + KEY_advertiserID + " = ? AND " + KEY_chefID + " = ?",
new String[] { ownerID, partnerID, advertiserID, chefID });
You are doing correct but just need to use AND or OR keyword between each where condition as per your requirement. So try using this once.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With