Заявката, както поискахте, е:
SELECT parent.item1, parent.item2, parent.index
FROM parent
INNER JOIN
child
ON child.index = parent.index
GROUP BY
parent.item1, parent.item2, parent.index
HAVING SUM(CASE WHEN child.value IN (1111111, 2222222) THEN 1 ELSE 0 END) = 2
AND COUNT(*) <= 2
Ако просто искате да сте сигурни, че децата отговарят на всички стойности в IN
списък и никой не е в списъка, използвайте това (в SQL Server
)
SELECT *
FROM parent p
WHERE NOT EXISTS
(
SELECT NULL
FROM (
SELECT value
FROM child c
WHERE c.index = p.index
) c
FULL JOIN
(
SELECT 11111111 AS value
UNION ALL
SELECT 22222222
) q
ON c.value = q.value
WHERE c.value IS NULL OR q.value IS NULL
)