我有以下两个实体:
project(identifier, name, ...)
member(identifier, name, ...)
它们由下表连接:
project-member(project_identifier, member_identifier)
找出某个成员(按标识符)属于哪些项目的最常见方法是什么?我看到了三种可能性:
select r1.*
from project r1
join project-member r2
on r2.member_identifier = 3 and r1.identifier = r2.project_identifier;
select *
from project r1
where r1.identifier in (select project_identifier from project-member where member_identifier = 3);
select *
from project r1
where exists (select * from project-member where member_identifier = 3 and project_identifier = r1.identifier);
我知道这主要取决于数据,并且应该使用真实数据分析查询计划,但我想知道默认选择是什么。我希望这是EXISTS
建筑,但我想听听你的意见。