NEED A SINGLE RECORD RETURNED FROM ONE TO MANY QUERY

G

Guest

I am having a mental block as to how to return just 1 instance of records
from the INVESTIGATOR table. Each investigator may have many projects, that
is captured in a JOINING table using the relationshipID. The JOINING table
is my middle table of a Many-to-Many Relationship with a table PROJECTS.

Presently, I'm getting multiple instances of INVESTIGATORS because they
obviously work multiple PROJECTS.

Here is the SQL from my query thus far:
SELECT tbl_Investigator.*, lk_Join.InvestigatorRelationID
FROM tbl_Investigator INNER JOIN lk_Join ON tbl_Investigator.InvestigatorID
= lk_Join.InvestigatorID
WHERE (((lk_Join.InvestigatorRelationID)=1));

Again; I am trying to create a query that will return only a single record
from the INVESTIGATOR table.

Thank you.
Bill
 
J

John Spencer

Add the distinct key word (record will not be updateable)

SELECT DISTINCT tbl_Investigator.*
, lk_Join.InvestigatorRelationID
FROM tbl_Investigator INNER JOIN lk_Join
ON tbl_Investigator.InvestigatorID = lk_Join.InvestigatorID
WHERE (((lk_Join.InvestigatorRelationID)=1));

Or Use a subquery if you want the tbl_Investgator records to be updateable
SELECT Tbl_Investigator.*
FROM tbl_Investigator
WHERE InvestigatorID in
(SELECT InvestigatorID
FROM lk_Join
WHERE InvestigatorRelationID =1)



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

Guest

Thank you John for your advice and time. I will try your suggestions as I
move forward.

Take care,
Bill
 

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