Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Counting foreign keys
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