Attributes | Pivot | Employees
| |
attribute1 | attribute1|employee1 | employee1
attribute2 | attribute2|employee1 |
attribute3 | |
我需要在Pivot表中排除与employee1没有连接的所有属性。在这种情况下属性3。SQL查询是什么?
使用not exists
:
select a.*
from attributes a
where not exists (select 1
from pivot p
where p.attribute_id = a.attribute_id and
p.employee_id = @employee_id
);