Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: Selecting number of "many" in 1-to-many
>I'm trying to figure out how to select the number
>of children each parent has.
>
>For example, say Table1 (Parent) has a 1-to-many
>relationship with Table2 (Children); that is, Table1
>can have many Table2 records.
>
>For each record in Table1, I want to know the number
>of times it appears in Table2 as a Parent, i.e. For each
>Parent (in Table1), how many Children (records in Table2)
>does it have?
>
select parent_name, count(*)
from parent
, children
where parent.parent_id = child.parent_id
group by parent_id;
Assuming all parents have children ;-)
Cheers Rob Received on Wed May 06 1998 - 10:45:17 CDT
![]() |
![]() |