DE
Size: a a a
DE
ОВ
DE
DE
DE
DE
DE
DE
ОВ
G
EG
DE
AP
select b.*
from table1 t
inner join table2 t1 on t1.for_id = t.id
inner join table2 t2 on t2.for_id = t.id
where t1.id != t2.id
and t1.order < t2.order
and (t1.user_id in (1, 2, 3, 4) or t2.user_id in (1, 2, 3, 4))
group by t.idAP
DE
AP
AP
DE
DE