寻找SQL加入

时间:2015-02-16 07:44:30

标签: sql

我有两个表格,分别是Educational_Info和Employee_Info。这些表的详细信息如下。

表:Educational_Info

DegreeID DegreeName
1 BBA
2 BCA
3 MBA
4 MCA

表:Employee_Info

EmpID BachelorDegree MasterDegree

1001 2 4

期望的输出:

EmpID BachelorDegree MasterDegree
1001 BCA MCA

如何获得所需的输出。如果不能使用此表结构,请以任何其他方式建议我。

提前致谢。

2 个答案:

答案 0 :(得分:1)

SELECT E.Empid,EI1.DegreeName,EI2.DegreeName 
FROM Employee_info E 
  INNER JOIN Educational_Info EI1 ON E.BachelorDegree=EI1.Degreeid
  INNER JOIN Educational_Info EI2 ON E.MasterDegree=EI2.Degreeid

答案 1 :(得分:1)

这个。这给你一些想法

select b.EmpID,a.DegreeName
FROM Educational_Info a
JOIN Employee_Info b on b.BachelorDegree = a.DegreeID or b.MasterDegree = a.DegreeID