Page 1 of 1

switching the value of a field between two rows - MySQL

Posted: Sat Sep 26, 2009 6:36 am
by SimonMayer
I have multiple rows in a MySQL database and I wish to be swap the value of one field between two rows
I am not looking to switch the primary key ID, but a separate ID stored in another field, which I am using to determine the displayed order on a webpage. I can think of ways to do it through PHP, but they are very clunky. Is there a MySQL query that will handle this?

I currently have:

Article_ID | Title | Order_ID
1 | Article One | 1
2 | Article Two | 2
3 | Article Three | 3


I wish to switch the Order_IDs of rows 2 and 3, so that I end up with:

Article_ID | Title | Order_ID
1 | Article One | 1
2 | Article Two | 3
3 | Article Three | 2

Re: switching the value of a field between two rows - MySQL

Posted: Sat Sep 26, 2009 6:56 am
by VladSun
What SQL queries have you tried so far?