Ok. Możesz zrobić tak:
create table list (
id int auto_increment primary key,
name varchar(50)
);
create table item (
id int auto_increment primary key,
list_id int,
value int,
foreign key (list_id) references list(id)
);
insert into list
(name)
values
('Przedmiot 1'),
('Przedmiot 2'),
('Przedmiot 3'),
('Przedmiot 4');
insert into item
(list_id, value)
values
(1, 1),
(1, 2),
(1, 3),
(1, 4),
(1, 5),
(1, 6),
(1, 7),
(1, 8),
(1, 9),
(2, 1),
(2, 2),
(2, 3),
(2, 8),
(3, 1),
(3, 2),
(3, 3),
(3, 4),
(4, 1),
(4, 2),
(4, 4),
(4, 9);
create table pattern (value int);
insert into pattern
(value)
values
(1),
(2),
(4),
(9);
i zapytanie:
select list.id, list.name from list order by(
select count(1)
from item, pattern
where item.list_id = list.id and item.value = pattern.value
) desc;
Przy czym pattern
powinien być tabelą tymczasową. Jego wypełnianie itd. możesz upchnąć w jakąś procedurę razem z zapytaniem.
Możesz też w procedurze przyjmować stringa z wzorcem ('1,2,4,9') i ręcznie doklejać go do zapytania np. CONCAT('...item.value IN (', pattern ,')...');