db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Knut Anders Hatlen <Knut.Hat...@Sun.COM>
Subject Re: how I can swap content of two fields in one table?
Date Sat, 08 Aug 2009 09:13:42 GMT
"sarah.kho" <sarah.kho@gmail.com> writes:

> Hi
> Is there an easy way to swap content of two fields (sn and ssn) in a table
> with hundreds of rows?

An update statement with "SET SN=SSN, SNN=SN" should do the trick. See
the example below.

ij> select * from t;
X   |Y   
---------
x1  |y1  
x2  |y2  
x3  |y3  

3 rows selected
ij> update t set x=y, y=x;
3 rows inserted/updated/deleted
ij> select * from t;
X   |Y   
---------
y1  |x1  
y2  |x2  
y3  |x3  

3 rows selected

Hope this helps,

-- 
Knut Anders

Mime
View raw message