| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> comp.databases.theory -> Re: Finding Orphans
"Lucky Leavell [RIS]" wrote:
>
> I have a situation whereby I am trying to determine the number of orphans
> in an addresses table by checking for those address keys NOT IN the five
> tables which use it, to wit:
>
> SELECT count(*)
> FROM address
> WHERE addr_key NOT IN (SELECT addr_key
> FROM client)
> AND addr_key NOT IN (SELECT addr_key
> FROM employee)
> AND addr_key NOT IN (SELECT addr_key
> FROM groups)
> AND addr_key NOT IN (SELECT addr_key
> FROM patient)
> AND addr_key NOT IN (SELECT addr_key
> FROM provider)
>
> These tables contain anywhere from a few hundred to a few million rows and
> only the address and patient tables have an index on the addr_key column.
> After running three hours the query returns a zero count which I know is
> NOT correct.
My first suggestion would be to add indexes to the other three tables, too. If those tables are large, I think you might run out of temp space or the db server might get confused.
Another way would be to split up the query:
SELECT COUNT(*)
FROM address
WHERE addr_key NOT IN
(SELECT addr_key
FROM client) AND
addr_key IN
(SELECT addr_key
FROM address
WHERE addr_key NOT IN
(SELECT addr_key
FROM employee)) ...
hth,
Heinz
Received on Wed Jan 10 2001 - 00:50:40 CST
![]() |
![]() |