RE: Swap data in columns

2010-09-23 Thread Jangita
ALTER TABLE tablename1 CHANGE column1 column2 VARCHAR(64), CHANGE column2 column1 VARCHAR(64) Assuming the columns are varchar(64) Jangita | +254 76 918383 | MSN Y!: jang...@yahoo.com Skype: jangita | GTalk: jangita.nyag...@gmail.com -Original Message- From: nixofortune

Re: Swap data in columns

2010-09-23 Thread nixofortune
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) kfoneil...@gmail.comwrote:

RE: Swap data in columns

2010-09-22 Thread Rolando Edwards
I ran these commands: use test DROP TABLE IF EXISTS mydata; CREATE TABLE mydata (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,column1 CHAR(1),column2 CHAR(2)); INSERT INTO mydata (column1,column2) VALUES ('a','z'), ('b','y'), ('c','x'), ('d','w'), ('e','v'); SELECT * FROM mydata; UPDATE mydata A

Re: Swap data in columns

2010-09-22 Thread Johnny Withers
Couldn't you just rename the columns? JW On Wed, Sep 22, 2010 at 11:53 AM, Rolando Edwards redwa...@logicworks.netwrote: I ran these commands: use test DROP TABLE IF EXISTS mydata; CREATE TABLE mydata (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,column1 CHAR(1),column2 CHAR(2)); INSERT

Re: Swap data in columns

2010-09-22 Thread Steve Staples
What about: select `id`, `column1` as 'column2', `column2` as 'column1'; Steve On Wed, 2010-09-22 at 13:06 -0500, Johnny Withers wrote: Couldn't you just rename the columns? JW On Wed, Sep 22, 2010 at 11:53 AM, Rolando Edwards redwa...@logicworks.netwrote: I ran these commands:

Re: Swap data in columns

2010-09-22 Thread nixofortune
Hi Rolando, This is perfect solution I was looking for. Why do you use left join here? It looks like inner join works fine as well. Thanks. Rolando Edwards wrote: I ran these commands: use test DROP TABLE IF EXISTS mydata; CREATE TABLE mydata (id INT NOT NULL AUTO_INCREMENT PRIMARY

Re: Swap data in columns

2010-09-22 Thread Egor Shevtsov
Hi Rolando, This is perfect solution I was looking for. Why do you use left join here? It looks like inner join works fine as well. Thanks. Rolando Edwards wrote: I ran these commands: use test DROP TABLE IF EXISTS mydata; CREATE TABLE mydata (id INT NOT NULL AUTO_INCREMENT PRIMARY

Re: Swap data in columns

2010-09-22 Thread Johnny Withers
This is even better! JW On Wed, Sep 22, 2010 at 2:27 PM, Steve Staples sstap...@mnsi.net wrote: What about: select `id`, `column1` as 'column2', `column2` as 'column1'; Steve On Wed, 2010-09-22 at 13:06 -0500, Johnny Withers wrote: Couldn't you just rename the columns? JW

RE: Swap data in columns

2010-09-22 Thread Rolando Edwards
- From: Egor Shevtsov [mailto:nixofort...@googlemail.com] Sent: Wednesday, September 22, 2010 4:14 PM To: MySQL mailing list Subject: Re: Swap data in columns Hi Rolando, This is perfect solution I was looking for. Why do you use left join here? It looks like inner join works fine as well. Thanks

Re: Swap data in columns

2010-09-22 Thread Kevin (Gmail)
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