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

Home -> Community -> Usenet -> c.d.o.misc -> Re: query to find references

Re: query to find references

From: <sampsonr_at_spamfool.xyz>
Date: 1997/05/30
Message-ID: <338f3c56.95663717@news.spry.com>#1/1

On Wed, 28 May 1997 08:53:54 +0200, Michiel Perdeck <perdeck.via_at_sni.de> wrote:

>I have a table A and a table B. Rows in B contain a foreign key to A.
>I want to find all instances of A to which less than a certain number,
>say N, rows in B refer. A naive query would look like this but is not
>accepted by Oracle7 ('a' is the name of the key field):
>
>SELECT * FROM A
>WHERE (SELECT COUNT(*) FROM B
> WHERE B.a = A.a) < N

Try this instead:

SELECT a.pkey, count(b.uniquecol)
FROM a, b
WHERE a.pkey = b.fkey
GROUP BY a.pkey
HAVING count(b.uniquecol) > N Received on Fri May 30 1997 - 00:00:00 CDT

Original text of this message

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