我有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