我有五张看起来像这样的表
BugHistory
--------------------
BugHistoryID
BugId
EmployeeId
Bugs
--------------------
BugID
Description
ProjectID
PriorityID
Employee
-------------------
EmployeeId
EmployeeName
Projects
-------------------
ProjectID
ProjectName
Priority
-------------------
PriorityID
PriorityName
我想从所有表中检索数据,使BugHistory
成为主表。
我需要[Description],[ProjectName],[PriorityName]
来自其余四个表中EmployeeID
为关键字的表。
应根据BugHistory表中的EmployeeID检索数据;我将根据登录获取EmployeeID。任何人都可以帮我写这个查询吗?
答案 0 :(得分:4)
这应该可以满足您的需求。
SELECT b.Description
, pj.ProjectName
, pr.PriorityName
FROM BugHistory bh
INNER JOIN Employee e
ON bh.EmployeeId = e.EmployeeId
INNER JOIN Bugs b
ON bh.BugId = b.BugId
INNER JOIN Project pj
ON b.ProjectId = pj.ProjectId
INNER JOIN Priority pr
ON b.PriorityId = pr.PriorityId