Created
November 2, 2020 18:51
-
-
Save EdoardoVignati/0eede9ba80c9339a29842f61c1e5105f to your computer and use it in GitHub Desktop.
Updates all rows based on a condition over the same table in MySql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UPDATE tbl | |
SET field_to_update = CASE | |
WHEN (SELECT COUNT(*) FROM (SELECT * FROM tbl) AS copy WHERE copy.field=<condition> HAVING COUNT(*)>0) THEN "this_value_if_true" | |
ELSE field_to_update | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment