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 -> Counting foreign keys

Counting foreign keys

From: <bhavinsh_at_my-deja.com>
Date: Thu, 28 Dec 2000 22:51:46 GMT
Message-ID: <92gg60$412$1@nnrp1.deja.com>

I need to count the number of foreign keys in one table (TABLEB) that exist for each and *every* primary key in another table (TABLEA).

I've tried group by:

SELECT pk, count(*) FROM TABLEB GROUP BY pk ORDER BY to_number(pk);

This gives me the number of foreign keys that only exist in TABLEB, (i.e. counts > 0) I would also like the keys with counts of 0.

TABLEA
(

pk
)

TABLEB
(

pk2
fk REFERENCES TABLEA(pk)
)

Thanks in advance.

Sent via Deja.com
http://www.deja.com/ Received on Thu Dec 28 2000 - 16:51:46 CST

Original text of this message

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