I have a table ( groups
) in SQL with the following structure:
id | name | description | display_order | ...
The display_order
field was set to UNIQUE
and should be an integer. Its main function is to be used to create a custom order in the table, using ORDER BY
:
SELECT * FROM groups ORDER BY display_order;
However, I need to create a query to raise or lower this order, so I also change the top and bottom records.
View a representative image of what I need to do: link .
+----+-----------------+-------------+--------------------+
| id | name | description | display_order (↓) |
+----+-----------------+-------------+--------------------+
| 1 | Administradores | ... | 1 |
+----+-----------------+-------------+--------------------+
| 3 | Outro Grupo | ... | 2 |
+----+-----------------+-------------+--------------------+
| 2 | Moderadores | ... | 3 |
+----+-----------------+-------------+--------------------+
| 4 | Grupo X | ... | 4 |
+----+-----------------+-------------+--------------------+
Assuming, therefore, that I need to upload the "Moderators" group up, as shown in the image, based on ID 2 , what would the query look like?