List:General Discussion« Previous MessageNext Message »
From:nixofortune Date:September 23 2010 9:09am
Subject:Re: Swap data in columns
View as plain text  
Hi Kevin,
It works in mysql but not exactly as I need.
In my case it copied content of column2 into column1.
So, not exactly what I intended to achieve.
Thanks.
Igor


update mydata set column1 = column2, column2 = column1

On Thu, Sep 23, 2010 at 12:03 AM, Kevin (Gmail) <kfoneill56@stripped>wrote:

> update mydata set column1 = column2, column2 = column1
> (works in sqlserver, can't try mysql at the moment)
> You can select which rows by adding a where clause obviously.
> I suppose that the field values are copied to a buffer which is the written
> to the table at the end of the update (or row by row?)
>
> ----- Original Message ----- From: "nixofortune" <
> nixofortune@stripped>
>
> To: <mysql@stripped>
> Sent: Wednesday, September 22, 2010 5:29 PM
>
> Subject: Swap data in columns
>
>
>  Hi all.
>>
>> Sorry for very simple question, just can't figure out the solution.
>> I need to swap data in column1 with data in column2.
>>
>>
>> +----+---------+---------+
>> | id | column1 | column2 |
>> +----+---------+---------+
>> |  1 | a       | z       |
>> |  2 | b       | y       |
>> |  3 | c       | x       |
>> |  4 | d       | w       |
>> |  5 | e       | v       |
>> +----+---------+---------+
>>
>> Can you achieve this with a simple query?
>> so for id 1 column1 = 'z' and column2 = 'a' and so on.
>>
>> Thanks guys,
>> Igor
>>
>>
>

Thread
Swap data in columnsnixofortune22 Sep
  • RE: Swap data in columnsRolando Edwards22 Sep
    • Re: Swap data in columnsJohnny Withers22 Sep
      • Re: Swap data in columnsSteve Staples22 Sep
        • Re: Swap data in columnsJohnny Withers22 Sep
    • Re: Swap data in columnsEgor Shevtsov22 Sep
      • RE: Swap data in columnsRolando Edwards22 Sep
  • Re: Swap data in columnsKevin \(Gmail\)23 Sep
    • Re: Swap data in columnsnixofortune23 Sep
  • RE: Swap data in columnsJangita23 Sep
Re: Swap data in columnsnixofortune22 Sep