SQL swap field values

Posted by Silence on Stack Overflow See other posts from Stack Overflow or by Silence
Published on 2010-05-21T14:40:36Z Indexed on 2010/05/21 14:50 UTC
Read the original article Hit count: 196

Filed under:
|

I have a SQL table (MYSQL 4.0 to be precise) composed of the following :

int no (primary)
int field1
int field2

I would like to swap the values of field1 with the values of field2 and vice-versa.

Ex.: 1;2.5;3.76 becomes 1;3.76;2.5

I need a swapping temporary variable of some sort. But I don't think I can use something like

Set @var1 = field1

inside my update statement. And I don't think altering the table to add a temporary column is my best best either.

© Stack Overflow or respective owner

Related posts about sql

Related posts about mysql