Created
January 6, 2019 14:43
-
-
Save amirkhiz/3c6042fafca86bb7c33c9fc11ce34e9a to your computer and use it in GitHub Desktop.
Sort Queries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Forwarding | |
#ex. : from = 1, to = 5 | |
UPDATE table_name SET order_field = order_field - 1 | |
WHERE order_field > {from} | |
AND order_field <= {to} | |
#Backward | |
#ex. from = 5, to = 1 | |
UPDATE table_name SET order_field = order_field + 1 | |
WHERE order_field >= {to} | |
AND order_field < {from} | |
#Run this after both update query: | |
UPDATE table_name SET order_field = {to} | |
WHERE id_field = {from_row_id} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment