Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: SQL Question
antonio wrote:
>
> Hi,
>
> I'm having some difficulties finding out the right SQL statement.
> This is the problem:
>
> I have two tables, let's say table1 and table2.
>
> table1 is the mastertable and table2 is the detail table.
>
> First I have to make a selection in the first table. Then i have to count
> the number of detailrecords.
> I want to display the selected masterrecords and the number of
> detailrecords.
>
> How can I do this?
select master.*, count(*)
from master m, outer detail d -- outer not needed if at least 1 detail
where m.pkey = d.fkey
group by 1,2,3,4,5,6,...... -- ie all master columns
order by m.pkey;
In other words join to the detail table but do not select any columns just the count. Use GROUP BY to make the count of details per master.
Art S. Kagel Received on Wed Feb 03 1999 - 15:58:37 CST