Multiple set wise where

时间:2019-05-31 11:23:06

标签: sqlite

I want to change two fields in one table with one query. It's looks like this

UPDATE SavedStoreModel 
SET storePosition =:secondItemPosition 
WHERE storePosition =:firstItemPosition, 
storePosition =:firstItemPosition 
WHERE storePosition =:secondItemPosition

But this query is don't executable because of coma. A query like this works fine without where condition, but how to do this with multiple where?

1 个答案:

答案 0 :(得分:1)

UPDATE SavedStoreModel 
SET storePosition = case when storePosition = :firstItemPosition 
                         then :secondItemPosition 
                         else :firstItemPosition 
                    end
WHERE storePosition in (:firstItemPosition, :secondItemPosition)