Return parent based on child

G

Guest

How can I build a query to return Jack from the following from two tables?
[ie pull only the records in the parent table with ALL related children
records t/f field equal “trueâ€]

Table1 (parents)
1 John
2 Jack
3 Sue


Table 2 (child)
1 Jeff true
1 Jack false
2 Cindy true
2 Jim true
3 Jane false
3 Steve false

I can see how to do it by adding a field to the parent table and marking any
parent records with a false if one of the child records is false and then
requery the parent table but I wanted to do it in a single step if possible.
 
M

Marshall Barton

ES said:
How can I build a query to return Jack from the following from two tables?
[ie pull only the records in the parent table with ALL related children
records t/f field equal “true”]

Table1 (parents)
1 John
2 Jack
3 Sue


Table 2 (child)
1 Jeff true
1 Jack false
2 Cindy true
2 Jim true
3 Jane false
3 Steve false

I can see how to do it by adding a field to the parent table and marking any
parent records with a false if one of the child records is false and then
requery the parent table but I wanted to do it in a single step if possible.


SELECT P.fname
FROM parents AS P INNER JOIN child As C
ON P.id = C.ID
GROUP BY P.id
HAVING Sum(IIf([t/f],1,0)) = Count(*)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top