1

I have fruits table, where rows are ordering by index :

SELECT index, title FROM fruits ORDER BY index;

 index | title  
-------+--------
     1 | Orange
-------+--------
     2 | Apple
-------+--------
     3 | Banana
-------+--------
     4 | Cherry
-------+--------
     5 | Strawberry

In client side I have sortable list, where user can drag items and change their order.

I need make query to change this order.

For example, I want to move Apple row after Cherry.
The result after query should be:

 index | title  
-------+--------
     1 | Orange
-------+--------
     2 | Banana
-------+--------
     3 | Cherry
-------+--------
     4 | Apple
-------+--------
     5 | Strawberry

How I can implement this?

1ven
  • 6,776
  • 1
  • 25
  • 39
  • 1
    http://stackoverflow.com/a/14092775/905902 there you are! (including a rather large list of duplicates) – wildplasser Jun 25 '16 at 12:34
  • Possible duplicate of [How do I get a column with consecutive, increasing numbers, without having any numbers missing?](http://stackoverflow.com/questions/14085258/how-do-i-get-a-column-with-consecutive-increasing-numbers-without-having-any-n) – wildplasser Jun 25 '16 at 14:00

0 Answers0