switching the value of a field between two rows - MySQL
Posted: Sat Sep 26, 2009 6:36 am
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
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