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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Limit Number of records in a join

Status
Not open for further replies.

Pipe2Path

Programmer
Aug 28, 2001
60
Here's my situation:

TableA --> TableB - 1-Many relationship

for the following query:

select * from tableA inner join TableB
on tableA.ID = TableB.ID

and my result brings back 2 records in TableB that match 1
record in TableA, how do I limit the query to output only 1 record from TableB?

e.g. ID nAME
1 John Smith
1 John Adams

So, I only want the first record from TableB to show up.

Thanks.



 
I'm not sure you can do that exactly, but you can do this:

SELECT TableA.ID, Max(nAME)
FROM...
GROUP BY TableA.ID

That will bring back only one name per ID, but it may not be the one you want.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top