Thursday, August 7, 2014

MySQL: swap valúes of 2 columns

If you want to swap values of 2 columns (e.g. col1 and col2) in a table (e.g. a_table), you can use below SQL:

UPDATE a_table SET col1=(@temp:=col1), col1 = col2, col2 = @temp;

Do you have another ways? Pls post comment here. Thanks!

No comments:

Post a Comment

Subscribe to RSS Feed Follow me on Twitter!