我正在尝试检索分配给项目任务的阶段,批处理,任务和员工,我几乎已经完成了但是我无法理解为什么每当我尝试包含employee
表。
这是我原来的陈述:
SELECT project.JONumber, stage.StageName, batch.BatchName, tasks.task_name, tasks_assignment.employee_number
FROM project
JOIN stage ON project.id = stage.project_id
JOIN batch ON stage.ID = batch.stage_id
JOIN tasks ON batch.id = tasks.batch_id
JOIN tasks_assignment ON tasks.id = tasks_assignment.task_id
WHERE project.id = 23441;
但是当我尝试添加另一个JOIN
语句时,结果返回空,
这是更新后的声明:
SELECT project.JONumber, stage.StageName, batch.BatchName, tasks.task_name, tasks_assignment.employee_number, employee.FirstName
FROM project
JOIN stage ON project.id = stage.project_id
JOIN batch ON stage.ID = batch.stage_id
JOIN tasks ON batch.id = tasks.batch_id
JOIN tasks_assignment ON tasks.id = tasks_assignment.task_id
JOIN employee ON employee.ID=tasks_assignment.employee_number
WHERE project.id = 23441;
我想,也许我搞砸了最后的JOIN声明,但并不是说JOIN应该像JOIN table2 ON table1.Primarykey=table2.foreignkey
一样。但也许我错了,有人能指出我的错误吗?我真的很困惑
答案 0 :(得分:0)
尝试这样一次
SELECT project.JONumber, stage.StageName, batch.BatchName, tasks.task_name, tasks_assignment.employee_number, employee.FirstName
FROM project
JOIN stage ON project.id = stage.project_id
JOIN batch ON stage.ID = batch.stage_id
JOIN tasks ON batch.id = tasks.batch_id
JOIN tasks_assignment ON tasks.id = tasks_assignment.task_id
RIGHT OUTER JOIN employee ON employee.ID=tasks_assignment.employee_number
WHERE project.id = 23441;