Addev
Addev

Reputation: 32233

Update multiple columns (with different primary key) in SQL (SQLite Android)

In a table [id, credit, debit] (all the values are integer)

I have (id1,id2,id3....) and (idA,idB,idC...).

I want to put all credit values to 0 for the ids (id1,id2,id3....) and all debit values to 0 for the ids (idA,idB,idC...). Is that possible in a single query or I must make two consecutive update queries?

Upvotes: 0

Views: 638

Answers (2)

Pikaling
Pikaling

Reputation: 8312

It may be possible to do simething like:

UPDATE table
    SET credit = 
        CASE id IN (id1,id2,id3) 
            THEN 0
        END, 
    debit = 
        CASE id IN (idA,idB,idC)
            THEN 0
        END

Although I think 2 queries would be easier to write and easier to understand

Upvotes: 1

Android Killer
Android Killer

Reputation: 18489

You may need two queries because in one query only one where clause can be there.Not more than one.As you have two conditions you may need 2 queries.

Upvotes: 1

Related Questions