2016-10-07 54 views

回答

2
UPDATE tweets 
SET pinned = NOT pinned 
WHERE id = 1234 OR pinned = TRUE; 

或者要特別小心

WHERE (id = 1234 AND pinned = FALSE OR (pinned = TRUE AND id <> 1234) 
+2

或者簡單地說:'更新tweets set pinned =(id = 1234)' –

+1

@a_horse_with_no_name這是一個好主意。雖然我認爲它仍然需要'WHERE id = 1234或pinned = TRUE'它使用索引而不是試圖在所有行上工作。 –