I'm wondering if I can do this in one query
Usecase: twitter pinned tweet. You can have at most one pinned tweet and setting a new pinned tweet, unset all the other previously pinned tweets.
Any ideas?
UPDATE tweets
SET pinned = NOT pinned
WHERE id = 1234 OR pinned = TRUE;
Or to be extra cautious
WHERE (id = 1234 AND pinned = FALSE) OR (pinned = TRUE AND id <> 1234)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With