9

I want to write a Query to delete a row from the table. I am confused of writing the statement. I need some help in writing this. I am providing my requirement here with plain sql statement.

(Pseudo code)

delete from tablename where value =="string1" && value2 == "string2" && value3 == "string3";

I want to write this in the Sqlite syntax for android db.delete(tablename, whereclause, whereargs);.

I would be thankful for your help.

4 Answers 4

28

a better way would be to use

String where = "value1 = ?"
+ " AND value2 = ?"
+ " AND value3 = ?";
String[] whereArgs = {string1,string2,string3};
Sign up to request clarification or add additional context in comments.

Comments

16
String table_name = "myTable";
String where = "value1 = 'string1'"
    + " AND value2 = 'string2'"
    + " AND value3 = 'string3'";
String whereArgs = null;
mDb.delete(table_name, where, whereArgs);

2 Comments

Thanks for the reply. I am going to use it. I have another question that what if I want to provide the integer. shall I directly place the integer variable directly into 'string2' position.
If "value2" is integer then you can write "value2 = 1". If "value2" is TEXT then you must write "value2 = '1'"
2
mdb.delete("tablename",new String("value1=? and Value2=? and value3=?"),new String[]{value1,value2,value3});

Comments

1
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL("DELETE FROM tablename WHERE value1='"+string1+"' AND value2='"+string2+"' AND value3='"+string3+"' "); //delete  row in a table with the condition
db.close();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.