Ad Code

Best way to swap values values between 2 rows

UPDATE table SET column = (CASE
WHEN column=$value1 THEN '$value2' "
WHEN column=$value2 THEN '$value1' END)
WHERE column IN ('$value1', '$value2')

That's it! Swaps the values in a single column for any two rows in a table. it's magical!

Post a Comment

0 Comments