sql - How to swap the column values for 2 records in a table? -


i'm trying swap column value 2 records in table. have primary key: 'recnr'

  recnr   file   1     img001.jpg   2     img002.jpg   5     img005.jpg   6     img006.jpg  

i want file img005.jpg move 1 place be:

  recnr   file   1       img001.jpg  2       img005.jpg  5       img002.jpg  6       img006.jpg 

how can done?

you add integer field called, example, weight, , use order clause.

this original dataset:

recnr | file        | weight 1     | img001.jpg  | 0 2     | img002.jpg  | 0 5     | img005.jpg  | 0 6     | img006.jpg  | 0 

and 1 row higher, make weight less

recnr | file        | weight 1     | img001.jpg  | 0 2     | img002.jpg  | -10 5     | img005.jpg  | 20 6     | img006.jpg  | 0 

then select * order weight asc make lightest records appear @ top. , result be

recnr | file        | weight 2     | img002.jpg  | -10 1     | img001.jpg  | 0 6     | img006.jpg  | 0 5     | img005.jpg  | 20 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -