I have a table of records in mySql. I need to maintain an order for them as specified by the user. So I've added a 'position' column.
What would be the SQL statement to update all the records when I move a specific record? I've got something like:
UPDATE items SET position = '2' WHERE id ='4';
UPDATE items SET position = position+1 WHERE position >= '2' AND id != '4';
But the greater than is going to be a less than if the record has moved down. What's the trick? Thanks!