嗨,我对多对多的关系有一个疑问。我有三个表Employee,Department和EDJoin表。这里EDJoin表包含Employee和Department表的id,我想加入这两个表来获取两个表数据。使用EDJoin表我将如何在这两个表之间建立连接,即Employee和Department。以下是Employee和Department表的列详细信息。 雇员: EMPID 名字 中间名字 姓 年龄
系: DepartmentID的 DEPARTMENTNAME
EDJoin: EMPID DepartmentID的
请告诉我这些故事的查询。如何为这三个表编写查询,以便我可以从Employee和Department表中获取数据。
谢谢&问候 Sailendra Narayan Jena
答案 0 :(得分:1)
你去......
select *
from Employee a
inner join EDJoin b on a.empIDd = b.empId
inner join Department c on b.departmentId = c.departmentId
诺尔
答案 1 :(得分:0)
SELECT * FROM Employee as a
INNER JOIN EdJoin as b ON a.Id = b.empId
INNER JOIN Deparment as c ON b.deptId = c.id;
如果要显示特定的列替换(*) 恩。
SELECT firstName,MiddleName,LastName,age,DeparmentName
FROM Employee as a
INNER JOIN EdJoin as b ON a.Id = b.empId
INNER JOIN Department as c ON b.deptId = c.id;