select * from TableA a
where exists (select 1 from TableB b where b.id=a.id and b.Param in (x,y))
and not exists (select 1 from TableB b2 where b2.id=a.id and b2.Param NOT in (x,y))
SELECT *
FROM TableA
WHERE ID IN
(
SELECT ID
FROM TableB
WHERE Param IN (x, y)
EXCEPT
SELECT ID
FROM TableB
WHERE Param NOT IN (x, y)
)
Find more questions by tags SQL Server
join tableB B on B. id=A. id and B. Param in (x,y)
left join tableB B2 on B2.id=A. id and B2.Param not in (x,y)
where B2.id is null - Lucio commented on July 9th 19 at 10:27