开发者

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 cons开发者_运维百科ecutive update queries?


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜