swap values in two columns using update SQL

Database
Enthusiast

swap values in two columns using update SQL

How can I swap both column values using only update statement? No Alter table permitted.

Table: T1 

A B

1 2

3 4

5 6

After execution the table will look like:

Table: T1

A B

2 1

4 3

6 5

Tags (2)
3 REPLIES
Enthusiast

Re: swap values in two columns using update SQL


UPDATE T1 SET a = b,b=a;

Enthusiast

Re: swap values in two columns using update SQL

Glass , Its awesome . I couldn't expect that solution is this much Easy....

Senior Apprentice

Re: swap values in two columns using update SQL

Hi Moutusi,

it's that easy :-)

Unless you try it on MySQL, which will screw up the data to

A B

2 2

4 4

6 6