Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread Finding Orphans
Wed, Feb 8 2006 9:15 PMPermanent Link

Dave
Hi

Lets say I have three tables:

tblMain:
Index: AutoInc
Name: String

tblSubject
Index: AutoInc
Subject: String

tblLink (which obviously links the items in the two tables above in a many to many relationship)
NameIndex: Integer
SubjectIndex: Integer


What SQL could i use to return a list of all the Names in tblMain that do not have an entry in tblLink?


Thanks SQL Gurus!


Wed, Feb 8 2006 10:33 PMPermanent Link

Jeff Cook
Dave <davey.crackpot@gmail.com> wrote on Wed, 8 Feb 2006 21:15:13 -0500

>Hi
>
>Lets say I have three tables:
>
>tblMain:
>Index: AutoInc
>Name: String
>
>tblSubject
>Index: AutoInc
>Subject: String
>
>tblLink (which obviously links the items in the two tables above in a many to many relationship)
>NameIndex: Integer
>SubjectIndex: Integer
>
>
>What SQL could i use to return a list of all the Names in tblMain that do not have an entry in tblLink?
>
>
>Thanks SQL Gurus!
>
>
>
Dave


SELECT M.Name FROM tblMain M
LEFT OUTER JOIN tblLink L ON L.NameIndex = M.Index
WHERE L.NameIndex IS NULL

Cheers

Jeff (no guru!)



--
Jeff Cook
Aspect Systems Ltd
Phone: +64-9-424 5388
Skype: jeffcooknz
www.aspect.co.nz



Thu, Feb 9 2006 5:21 AMPermanent Link

Dave
Thanks Jeff, works great.

Image