我有3個表:行動,部門,員工JPQL - 避免使用加入
action (
id
employee_id
name
)
employee(
id
department_id
)
department (
id
name
)
- action.employee_id可以爲空
我使用下面的查詢:
select a.id, a.name, d.name from action a, employee e, department d where a.employee_id=e.id and e.department_id=d.id
但是在沒有employee_id的情況下我沒有在結果中獲得這些行
有沒有辦法克服這一點,而不使用左連接?
試過到目前爲止(沒有工作):
select a.id, a.name, d.name from action a, employee e, department d where (a.employee_id=e.id and e.department_id=d.id) or a.employee_id is null
它爲什麼不工作?你看到了什麼輸出? – Damian
它返回了動作和部門名稱的所有組合(對於沒有'employee_id'的行)。如果我有x行動,並在所有他們'employee_id'爲空,y部門它返回x * y結果,而不是隻有x結果 – levtatarov