Please, see the following pastebin for a complete example. Why does Query 2 return different results than Query 1? I think Query 2 have correlated subqueries, so they should be executed once per row, but it works like subqueries is joined with OR not AND.
-- Query 1
SELECT id
FROM parent p
WHERE EXISTS(
SELECT 1
FROM child
WHERE child.parent_id = p.id AND child.field_1 = 1 AND child.field_2 = 1
)
-- Query 2
SELECT id
FROM parent p
WHERE EXISTS(
SELECT 1
FROM child
WHERE child.parent_id = p.id AND child.field_1 = 1
) AND EXISTS(
SELECT 1
FROM child
WHERE child.parent_id = p.id AND child.field_2 = 1
)
Actual results for Query 1:
id
--
2
3
4
Actual results for Query 2:
id
--
2
3
4
5