user2515300
user2515300

Reputation: 27

Sqlite query using where condition having more than one condition to satisfy

Please find what is wrong here

here _id and chek is the column of my db i to write a query to search those which has id =id and check =number

 public Cursor query(int id){
    return myDataBase.query("question", null,"_id = "+id+ "AND " +  "chek ="+number,null, null, null, null); 


}

Upvotes: 0

Views: 450

Answers (4)

Waqar Khan
Waqar Khan

Reputation: 478

Replace your query with these lines if not yet solved..

public Cursor query(int id){
return myDataBase.query("question", null,"(_id = "+id+ " AND " +  "chek ="+number+")",null, null, null, null);

Upvotes: 0

Bhavin Nattar
Bhavin Nattar

Reputation: 3215

May this help you:

Replace your query with these lines..

public Cursor query(int id){
return myDataBase.query("question", null,"_id = "+id+ " AND " +  "chek ="+number,null, null, null, null);

keep space between the double quotes in And :" And " otherwise the string will be
Example: _id=3And check =9

Upvotes: 1

Tarsem Singh
Tarsem Singh

Reputation: 14199

try

return myDataBase.query("question", null,"_id = "+id+ " AND " +  "chek ="+number,null, null, null, null); 

Upvotes: 0

Mohammod Hossain
Mohammod Hossain

Reputation: 4114

Firstly check your sql query syntax are right or not

You can use raw query

 String SQL= "select * from question where _id = "+id+ " and chek ="+number+";
    Log.d("SQL::", SQL);
    Cursor cursor = db.rawQuery(SQL, null);

Upvotes: 0

Related Questions