Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: SQL Question

Re: SQL Question

From: Art S. Kagel <kagel_at_bloomberg.net>
Date: Wed, 03 Feb 1999 16:58:37 -0500
Message-ID: <36B8C68D.32C9@bloomberg.net>


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

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US