MySQL: How to swap entires of two columns with just one query
2009 June 24
Check this out, I found out a really nice way how to swap values of two columns with just one query, using user defined variables. Given a table with two columns a and b. To swap their values in whole, use this query:
UPDATE my_table SET a=@tmp:=a, a=b, b=@tmp;
Done! Isn’t that easy?