만 다음 집계 (최대/최소) 기능을 사용할 수있는 하나 개의 전문을 반환 할 경우 SQL Server를 사용하고 있기 때문에 당신은 또한 하나를 반환 할 row_number()
기능을 사용할 수 있습니다 또는
Select P.ProfessionalID,
P.ProfessionalName,
max(S.SpecialtyName) SpecialtyName
from Professionals P
inner join ProfessionalSpecialtyRelation PR
on P.ProfessionalID = PR.ProfessionalID
-- and P.ProfessionalID = POR.ProfessionalID You are not joining to a table with POR alias
inner join Specialties S
on PR.SpecialtyID = S.SpecialtyID
where P.ProfessionalName Like '%arif%'
OR P.ProfessionalSurname Like '%%'
group by P.ProfessionalID, P.ProfessionalName;
을 각 직업에 대한 행 :
select ProfessionalID,
ProfessionalName,
SpecialtyName
from
(
Select P.ProfessionalID,
P.ProfessionalName,
S.SpecialtyName,
row_number() over(partition by P.ProfessionalID order by S.SpecialtyName) rn
from Professionals P
inner join ProfessionalSpecialtyRelation PR
on P.ProfessionalID = PR.ProfessionalID
-- and P.ProfessionalID = POR.ProfessionalID You are not joining to a table with POR alias
inner join Specialties S
on PR.SpecialtyID = S.SpecialtyID
where P.ProfessionalName Like '%arif%'
OR P.ProfessionalSurname Like '%%'
) d
where rn = 1;
참고 :이 WHERE 절에 조인과 내가 (내부 조인) 대신 쉼표로 구분 된 목록을 ANSI 사용하는 구문을 가입 할 수있는 쿼리를 변경했습니다.
둘 이상의 전문 분야가있는 경우 결과를 원하십니까? – Taryn
그 교수에게 단 하나의 행만 가져오고 싶습니다. 유일한 ID가 필요합니다 –
하나의 명물 만 선택하면됩니까? – LuigiEdlCarno