DROP TABLE IF EXISTS items;
CREATE TABLE items (
id INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
prefix INT,
value TINYINT UNSIGNED,
INDEX (prefix, value desc)
) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
INSERT INTO items (prefix, value) VALUES(1, 1);
INSERT INTO items (prefix, value) VALUES(1, 2);
INSERT INTO items (prefix, value) VALUES(1, 2);
INSERT INTO items (prefix, value) VALUES(1, 2);
INSERT INTO items (prefix, value) VALUES(1, 3);
SELECT *
FROM items
WHERE prefix = 1 AND value > 1
ORDER BY value DESC;
id	prefix	value
5	1	3
2	1	2
3	1	2
4	1	2
DROP TABLE items;
