Closed Thread Icon

Topic awaiting preservation: MySQL value swapping (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=21979" title="Pages that link to Topic awaiting preservation: MySQL value swapping (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: MySQL value swapping <span class="small">(Page 1 of 1)</span>\

 
marf
Bipolar (III) Inmate

From: Canada
Insane since: Oct 2001

posted posted 05-29-2004 16:05

LEts say I have 2 entries in my MySQL table. Their primart ID is incremental. I want to swap all values in id#2 with id#3. Does MySQL have a query statement to do that?

"If rabbits' feet are so lucky, then what happened to the rabbit?"

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 05-29-2004 16:20

http://sqlcourse.com/update.html
What do you want to do with the record of id #2 ? Beware, you must not avoir some identical values in a primary ( unique ) ID.

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 05-29-2004 16:31

marf: If it is like:

id | value1 | value2
2 | 34 | 34
3 | 45 | 45

and you want the values the other way round:

id | value1 | value2
2 | 45 | 45
3 | 34 | 34

it might be easier doing it by hand through PMA or (if you have too many entries) you could create a temporary table. If I have the wrong end of the stick then feel free to explain at greater length.

quote:
poi said:

Beware, you must not avoir some identical values in a primary ( unique ) ID.



The perils of multilingualism

___________________
Emps

The Emperor dot org | Justice for Pat Richard | FAQs: Emperor | Site Reviews | Reception Room

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 05-29-2004 16:40
quote:
Emperor said:
The perils of multilingualism


oops, that combined with the perils of replying while I'm Out Of Mana in Dark Age Of Camelot

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 05-29-2004 20:26

Um this is something done a bit easier with just changing the database column names instead of manually swapping all the values.

ALTER TABLE `databasename`.`table` CHANGE `col2` `col3` VARCHAR(200) NOT NULL

You'll probably have to do this 3 times col1 to temp col2 to col2 and temp to col2 but it's easier than swapping all the data.



.:[ Never resist a perfect moment ]:.

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 05-30-2004 12:16

he wants to swap rows, not columns!

And I'd just swap the keys... but I'm lazy.

« BackwardsOnwards »

Show Forum Drop Down Menu