Best way to keep sort order / priority?

I am using MySQL. I have a table where I need to be able to manually sort the priority / order of the rows. Initially, I thought about assigning each row to an arbitrary order (1, 2, 3, etc.), and then just β€œswapping” the order with the moved row, but I don’t think this is the best way to do this.

After some reading on related issues here ( like this one ), many people said to assign a value to a priority column based on the identifier column (id * 1000). And to change the order of the rows, you split / subtract the difference between the columns. I do not quite understand how this works.

This is the layout of the table to be sorted.

CREATE TABLE liability_detail ( id int NOT NULL AUTO_INCREMENT, analysis_id int NOT NULL, //(many-to-one relationship with analysis table) other_columns various datatypes sequence int DEFAULT 0 ) 

I would like to set up an easy way to control the priority of strings so that I can easily sort them without creating a lot of code to manage everything.

+7
source share
1 answer

As a result, I answered this question: stack overflow

I set the column sort-order = id * 1000 to get unique orders. So far this has worked very well, and he has not had any problems.

+3
source

All Articles