SELECT *
FROM table
WHERE
item_id IN (2, 3, 5)
AND
item_id NOT IN (SELECT item_id FROM table);
SET @var = '{2}{3}{5}';
SELECT
SUBSTRING
(
@var := REPLACE
(
(
SELECT @var := REPLACE(@var, concat('{', `item_id`, '}'), '') AS `ids`
FROM `table`
ORDER BY `ids` DESC
LIMIT 0,1
),
'}{',
','
),
2,
length(@var) - 2
)