An Inner Join on an Inner Join

D

David Wetmore

In an M2M relationship between headers and quads I
wish to select the header keys & names where the header record
contains both of two quadkeys (CKey) from the join table, tblQuadsJoin.

I've been trying to do this with an inner join on an inner join
but the SQL below doesn't work.

SELECT tblHeaders.HKey, tblHeaders.Name
FROM tblHeaders
(INNER JOIN tblQuadsJoin
ON tblHeaders.HKey = tblQuadsJoin.PKey
WHERE tblQuadsJoin.CKey = 61)
INNER JOIN tblQuadsJoin
ON tblHeaders.HKey = tblQuadsJoin.PKey
WHERE tblQuadsJoin.CKey = 84

Am I on the right track or do I need to build an intermediate table
based on the first join and then do the second join on the intermediate table?

Thanks, Dave
 
J

John Spencer

As best as I can figure your query should look like the following.

SELECT tblHeaders.HKey, tblHeaders.Name
FROM tblHeaders INNER JOIN tblQuadsJoin
ON tblHeaders.HKey = tblQuadsJoin.PKey
WHERE tblQuadsJoin.CKey = 84 or
tblQuadsJoin.CKey = 61


John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top