Hjalti
Hjalti

Reputation:

Access SQL many to many query

I have three tables:

Author(AID, Name)
Title(TID, Name)
AuthorOfTitle(ID, AID, TID)

My question is how do can I see only Authors that are connected to no titles, that is Authors where there is no record in AuthorOfTitle. How to do this in SQL. Btw am using MS Access 2007.

Upvotes: 1

Views: 176

Answers (2)

Jerub
Jerub

Reputation: 42638

You can use the foo not in (select ... from bar) SQL subquery expression to do this.

SELECT AID, Name FROM Author 
WHERE Author.AID NOT IN (SELECT AuthorOfTitle.AID FROM AuthorOfTitle)

Upvotes: 0

Eric Petroelje
Eric Petroelje

Reputation: 60518

This ought to do it:

SELECT A.*
FROM Author A LEFT JOIN AuthorOfTitle T ON A.AID = T.AID
WHERE T.ID IS NULL

Upvotes: 1

Related Questions