I would like to select a parent and all of its child nodes if any particular child matches a set of criteria. Is this possible with a single query?
Using two queries it would look like this:
SELECT p_id INTO target
FROM parent, children
WHERE parent.p_id = children.p_id and children.data1 = 'blah';
SELECT *
FROM parent
JOIN children ON parent.p_id = children.p_id and children.p_id = target;
.
p_id name
1 Perice
2 Siward
3 Scottie
c_id p_id name
1 1 Arda
2 1 Katrinka
3 2 Gladi
4 3 Hedi
5 3 Didi
6 3 Lorry
if the predicate was a child name match for Lorry, then the result set would contain
p_id c_id p_name c_name
3 4 Scottie Hedi
3 5 Scottie Didi
3 6 Scottie Lorry