MySQL Lists are EOL. Please join:

List:General Discussion« Previous MessageNext Message »
From:Don Read Date:March 16 2003 6:53am
Subject:RE: Fw: Swapping around values in a database
View as plain text  
On 15-Mar-2003 Mr Orange wrote:
> Hello all : )
> 
> Can anyone offer any advice on how to achieve the following with SQL?
> 
> Say I have a table.....
> 
> CREATE TABLE page (
>   pgposition int(6) not null,
>   pgelement char(20) not null default '',
>   pgsize int(4) not null default '0'));
> 
> and it has this data in.....
> 
>   1,"TEXT",20
>   2,"TEXT",30
>   3,"PASSWORD",10
> 
> How do I get 2 and 3 to change over, so the data becomes.....
> 
>   1,"TEXT",20
>   2,"PASSWORD",10
>   3,"TEXT",30
> 
> Thanks in advance,
> Steve.
> 
> 

Untested:

UPDATE page 
  SET pgposition=IF(pgposition=3, 2, 3)
  WHERE pgposition IN (2,3);

Regards,
-- 
Don Read                                       dread@stripped
-- It's always darkest before the dawn. So if you are going to 
   steal the neighbor's newspaper, that's the time to do it.
                            (53kr33t w0rdz: sql table query)
Thread
Fw: Swapping around values in a databaseMr Orange15 Mar
  • RE: Fw: Swapping around values in a databaseDon Read16 Mar