从数据透视表中员工表没有连接的属性中排除所有

  • 本文关键字:连接 属性 排除 数据 透视 sql sqlite
  • 更新时间 :
  • 英文 :

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
);

最新更新