Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite database update query with multiple where conditions in Android

I want to update my database table with multiple where conditions. I already did with single where condition

db.update(TABLE_MISSING_ITEMS, values, KEY_AUTHOR + " = ?",
                new String[] { String.valueOf(items.getAuthor()) }); 

Now i want 2 where condition.

P.S :- No raw query

like image 908
Rohit Avatar asked Sep 09 '14 05:09

Rohit


People also ask

WHERE multiple conditions SQLite?

The AND operator allows the existence of multiple conditions in a SQLite statement's WHERE clause. While using AND operator, complete condition will be assumed true when all the conditions are true. For example, [condition1] AND [condition2] will be true only when both condition1 and condition2 are true.

How do I update multiple columns in SQLite?

First, specify the table where you want to update after the UPDATE clause. Second, set new value for each column of the table in the SET clause. Third, specify rows to update using a condition in the WHERE clause. The WHERE clause is optional.

Which method is used to insert update and modify data in SQLite?

The data modification clauses in SQLite are INSERT, UPDATE, and DELETE statements. It is used for inserting new rows, updating existing values, or deleting rows from the database.

Can multiple processes write to SQLite?

SQLite allows multiple processes to have the database file open at once, and for multiple processes to read the database at once. When any process wants to write, it must lock the entire database file for the duration of its update.


1 Answers

You can separate the different WHERE conditions with ANDlike this:

db.update(TABLE_NAME,
    contentValues,
    NAME + " = ? AND " + LASTNAME + " = ?",
    new String[]{"Manas", "Bajaj"});
like image 164
Manas Bajaj Avatar answered Nov 15 '22 15:11

Manas Bajaj