By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE IF NOT EXISTS article (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`order` INT(11) UNIQUE,
PRIMARY KEY (`id`)
);
INSERT INTO article
VALUES
(1, 0),
(2, 1),
(3, 2),
(4, 3),
(5, 4),
(6, 5),
(7, 6),
(8, 7),
(9, 8),
(10, 9);
SELECT *
FROM article;
UPDATE article
SET article.order = NULL
WHERE id = 3;
UPDATE article
SET article.order = article.order -1
WHERE
article.order > 2
AND
article.order <= 6
;
Records: 10 Duplicates: 0 Warnings: 0
id | order |
---|---|
1 | 0 |
2 | 1 |
3 | 2 |
4 | 3 |
5 | 4 |
6 | 5 |
7 | 6 |
8 | 7 |
9 | 8 |
10 | 9 |
Rows matched: 1 Changed: 1 Warnings: 0
Rows matched: 4 Changed: 4 Warnings: 0
Rows matched: 1 Changed: 1 Warnings: 0
id | order |
---|---|
1 | 0 |
2 | 1 |
4 | 2 |
5 | 3 |
6 | 4 |
7 | 5 |
3 | 6 |
8 | 7 |
9 | 8 |
10 | 9 |