Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Distinct Problem

Author  Topic 

kannis1
Starting Member

4 Posts

Posted - 2006-07-03 : 11:14:15
I'm doing a join between two tables where the relationship is one to many. In my case I want to get distinct counselors with their specialtyId (please see below). However with the following query I get multiples of the counselors because they have multiple specialties. How can I get distinct counselors with their specialtyId?

Select Distinct(a.counselorId),a.firstName,a.lastName,a.professionalTitle,a.city,a.state,a.shortBio,a.tagline,b.specialtyId
From awCounselor a (noLock)
Join awCounselorSpecialty b (noLock)
On a.counselorId = b.counselorId
And a.activityStatus = 1

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-07-03 : 11:24:46
"I get multiples of the counselors because they have multiple specialties. How can I get distinct counselors with their specialtyId?"
So for each counselors, which specialty do you want ?


KH

Go to Top of Page

kannis1
Starting Member

4 Posts

Posted - 2006-07-03 : 11:29:17
Ah, I see the problem. When you asked me that question it cleared it up in my head. I know what I need to do. Thanks!
Go to Top of Page
   

- Advertisement -