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!

Select the first matching record

Status
Not open for further replies.

FlyingFrog

Programmer
Jun 24, 2003
17
0
0
US
Hello friends
I have two tables ProjectInfo and ProjectContacts
A Project can have multile contacts.
I want to retrieve only only contact(any contact) for each projectId.

How can I do this?
Thanks
 
select ProjectInfo.projID, max(contact)
from ProjectInfo left join ProjectContacts
on ProjectInfo.projID = ProjectContacts.projID
group by ProjectInfo.projID
 
The following query will select only the 1st contact for each projID:

Select i.projID, c.contact
from ProjectInfo i left join ProjectContacts c
On i.projID = c.projID
Where c.Contact In (Select Top 1 contact From ProjectContacts where projID = i.projID)
 
Thanks lienyi and David for your quick response.
David, I followed your approach and it works fine.
thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top