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

One - Many Relationship 1

Status
Not open for further replies.

Zurich98

Programmer
Apr 8, 2006
64
US
Hello All,


My envinronment is SQL 2005. The data in my table is as follow:

ID Test
1 Tax Exempt
1 Tax Composition

I would like to pull only one Test for this ID. It does not matter which test. I don't have a date field or any other unique key to differentiate between the two test for this ID

select *
from student s
left join Test t
on s.ID = t.ID

result:

1 John Doe Tax Exempt
1 John Doe Tax Composition

desire result:

1 John Doe Tax Exempt

or

1 John Doe Tax Composition

Any input/suggestion is greatly appreciated. Thanks
 
You could use the MIN of the Test....

Code:
select *
from   student s
       left join (
           Select Id, Min(Test) As Test 
           From   Test 
           Group By Id) t
         on s.ID = t.ID

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
I was about to go the long way by using identity(smallint,1,1) as RowNmbr and then pick the min or max by RowNmbr. I didn't realize I can use min and max function on text field. Someone else in another forum suggests the same idea. Thank you for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top