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