Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding orphans 1

Status
Not open for further replies.

Sen7inel

IS-IT--Management
Feb 14, 2001
90
0
0
FI
If I have table_a.id and table_b that has table_a_id, how can I find all entries from table_b that have a non-existant table_a_id?
 
How about:
[tt]
SELECT table_b.*
FROM
table_a
LEFT JOIN table_b ON table_a.id=table_b.table_a_id
WHERE table_a.id IS NULL
[/tt]


-----
ALTER world DROP injustice, ADD peace;
 
I guess my post was a bit unclear =(. I meant finding such rows from table_b, that have a table_a_id that simply doesn't exist at all in table_a's id column.
 
That code should do what you want. Have you tried it?

-----
ALTER world DROP injustice, ADD peace;
 
Yes, I tried it, and it returned a bunch of all-NULL rows. However, RIGHT JOIN seems to work (or then I typo'd something really bad somewhere). =)
 
You're right, it should have been RIGHT JOIN. Sorry about that!

-----
ALTER world DROP injustice, ADD peace;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top