I have a table like:
categoryID categoryName
----------------------------
1 A
2 B
3 C
Now I want the user to be able to order this data in accordance with his will. I want to remember his preferred order for the future. So I thought to add a column orderto the table above and make it a type of INTand AUTO_INCREMENT. So now I get the table as follows:
categoryID categoryName order
-------------------------------------
1 A 1
2 B 2
3 C 3
4 D 4
My problem is that now the user decides to bring categoryNamein order 4 (D in the example above) to 2 (above B in the example above) so that the table looks like this:
categoryID categoryName order
-------------------------------------
1 A 1
2 B 3
3 C 4
4 D 2
My question is: how should I assign new values to a column orderwhen reordering occurs. Is there a way to do this without updating all the rows in the table?
, , , a FLOAT 1,5, 1,2. .
EDIT:
(m, n), m, n - . (m-n) , ?
2:
, FLOAT, sql, , id = 2 ().
select ((
select `order` as nextHighestOrder
from `categories`
where `order` > (
select `order` as targetOrder
from `categories`
where `categoryID`=2)
limit 1) + (
select `order` as targetOrder
from `categories`
where `categoryID`=2)) / 2;
3.5, .
? , select order as targetOrder from categories where categoryID=9 .