android sqlite query with multiple where

后端 未结 4 851
失恋的感觉
失恋的感觉 2020-12-30 03:40

Here\'s my current sqlite code:

Cursor c = sqlDatabase.rawQuery(\"select docid as _id, recipeID from \" + TABLE_RECIPE_NAME + 
                \" where \" +          


        
相关标签:
4条回答
  • 2020-12-30 03:47

    Use AND and OR for multiple WHERE clauses. Use parentheses if logical grouping or order is needed.

    SELECT *
    FROM employees
    WHERE (last_name = 'Smith' AND first_name = 'Jane') OR (employee_id = 1); 
    

    (source)

    Note

    • This supplemental answer omits the Android code formatting because it makes the SQL hard to read and understand. The reader can do their own formatting.
    0 讨论(0)
  • 2020-12-30 03:48

    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 });
    
    0 讨论(0)
  • 2020-12-30 03:54

    Probably you have to use AND. You want a query that should return the value in Cursor populated with comparing multiple values. So, you just need to use AND. Instead of using a comma(,). Above answer seems correct but it just lacks the explanation.

    0 讨论(0)
  • 2020-12-30 04:12

    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.

    0 讨论(0)
提交回复
热议问题