I'm curious if I can update all matching fields in a row with a new value at once in MySQL.
I know I can use ALTER TABLE
to change default values, but I'm interested only in one row, not in changing the default values of an entire table. I can iterate through each in a loop if necessary, but I'm curious if there is a way to accomplish this more elegantly.
Imagine my row looks like this:
| 1 | Joe | Smith | null | X | X | X | Y | X | Y | Y | X | null | Y | X | null |
Is it possible to update all fields matching X
to Y
at once?
So the result would look like this:
| 1 | Joe | Smith | null | Y | Y | Y | Y | Y | Y | Y | Y | null | Y | Y | null |
(assume 1
is a primary key, id... if that helps at all)
Can this be done with only one UPDATE
query?