Home » RDBMS Server » Server Administration » Finding Orphan Records
Finding Orphan Records [message #373108] Tue, 27 March 2001 16:56 Go to next message
pui
Messages: 2
Registered: March 2001
Junior Member
What's the most efficient way to find orphan records in TABLE_B. Parent table = TABLE_A, child table = TABLE_B?
Re: Finding Orphan Records [message #373126 is a reply to message #373108] Wed, 28 March 2001 13:47 Go to previous messageGo to next message
Salman Khan
Messages: 51
Registered: September 2000
Member
Try this.

Select Missing_Record from table_a
where missing_record not in (select missing_record from table_b);

Bye
Salman Khan
Re: Finding Orphan Records [message #373142 is a reply to message #373108] Thu, 29 March 2001 07:58 Go to previous message
Phenoracle
Messages: 35
Registered: March 2001
Member
I often
find NOT IN slows down my queries.
ther are may options for doing this and if the speed of which you wish to
retreive your data is of importants then try one of these

DETERMINE HOW MANY RECORDS THE DRIVING TABLE WILL VALIDATE AGAINST
DO YOU NEED TO USE INDEXES OR FULL TABLE SCANS
AND MANY MORE.

Select a.Missing_Record from table_a a
where not exists (select 1 from table_b b where b.missing_record = a.missing_record);

If your Driving table has no restrictions and will query
against a large amount of data try this
(forget the cost)

Select a.Missing_Record
from table_a a
, (Select a.Missing_Record
from table_a c
MINUS
Select a.Missing_Record
from table_b d)e
where e.missing_record = e.missing_record;

Hope this is of help

Phenoracle
Previous Topic: Data types
Next Topic: Does Oracle SQL has crosstab query using transform statement like in Access
Goto Forum:
  


Current Time: Sat Jun 29 00:26:28 CDT 2024