2017-04-21 27 views
-1

我有2個查詢,其中第一個是將所有字段設置爲零,第二個更新列但我希望這些查詢進入查詢更改cover_image = 0 first then cover_image = 1關於電臺值的Mysql查詢:重置所有值並更改一個

Update gallery set cover_image = 0 Where gallery_id = 1; 
Update gallery set cover_image = 1 Where ID = 4 AND gallery_id = 1; 

我該如何處理單個查詢?

+0

請更改標題更明確的,如果你只是想合併這些查詢的。 –

回答

2

我剛找到答案。

UPDATE gallery SET cover_image = IF(id='4', '1','0') WHERE gallery_id = 1 

它等於

Update gallery set cover_image = 0 Where gallery_id = 1; 
Update gallery set cover_image = 1 Where ID = 4 AND gallery_id = 1; 
相關問題