try
select id
from YourTable
where relatedid in ( @input_1, @input_2)
group by id
having count(*) >=2 -- for 3 inputs, make this 3 etc
пример, который вы можете запустить
create table #yourtable(Id int, RelatedId int)
insert #yourtable values(1,1)
insert #yourtable values(1,2)
insert #yourtable values(1,3)
insert #yourtable values(2,2)
insert #yourtable values(2,3)
insert #yourtable values(2,4)
insert #yourtable values(3,5)
declare @input_1 int, @input_2 int
select @input_1 = 2,@input_2 = 3
select id
from #yourtable
where relatedid in ( @input_1, @input_2)
group by id
having count(*) >=2