简单问题。多个类别名称的查询
两张表 T_resume_language,T_language_sort
第一张表有三个字段 第二章表是类别表
现在我想查询出来类别的名字是不是必须这样写三次啊。
有没有什么好的方法。这个看起来不怎么好看。
select languageId1 ,languageId2, languageId3
,(select a.cname from T_language_sort as a ,T_resume_language as b where a.code=b. languageId1 and b.[resumeid]=@id ) as language1,
(select a.cname from T_language_sort as a ,T_resume_language as b where a.code=b. languageId2 and b.[resumeid]=@id ) as language2,
(select a.cname from T_language_sort as a ,T_resume_language as b where a.code=b. languageId3 and b.[resumeid]=@id ) as language3
from T_resume_language as a where [resumeid]=@id
------解决方案--------------------select a.languageId1, a.languageId2, a.languageId3, b.cname, c.cname, d.cname
from T_resume_language a
left join T_language_sort b on a.languageId1 = b.code
left join T_language_sort c on a.languageId2 = c.code
left join T_language_sort d on a.languageId3 = d.code
where a.[resumeid] = @id
------解决方案--------------------select languageId1 ,languageId2, languageId3,
b.cname as language1,c.cname as language2,d.cname as language3
from T_resume_language as a inner join T_language_sort as b on b.code=a. languageId1
inner join T_language_sort as c on c.code=a. languageId2
inner join T_language_sort as d on d.code=a. languageId3
where [resumeid]=@id