将 Not In Sub-Select 重写为 Join for Propel
给定以下模式:
person:
id: ~
group:
id: ~
group_membership:
person_id: ~
group_id: ~
我试图使用 Propel 的条件查找不在某个组内的成员,以下 SQL 将执行此操作:
SELECT * FROM person
WHERE id NOT IN (
SELECT person_id FROM group_membership
WHERE group_id = 1
);
不幸的是,Propel 不支持子选择。可以先执行子选择并将其直接作为数组传递,但我宁愿在一次调用中完成。我发现这篇文章,它建议使用自定义条件或将其转换为联接。
是否可以将上面的 SQL 转换为没有嵌套选择的单个 Join?
Given the following schema:
person:
id: ~
group:
id: ~
group_membership:
person_id: ~
group_id: ~
I am attempting to find members not within a certain group using Propel's Criteria, which the following SQL will do:
SELECT * FROM person
WHERE id NOT IN (
SELECT person_id FROM group_membership
WHERE group_id = 1
);
Unfortunately, Propel doesn't support sub-selects. It's possible to perform the sub-select first and pass it directly as an array, but I would rather do it in one call. I found this article, which suggests using a custom criteria or converting it to a join.
Is it possible to convert the above SQL to a single Join with no nested selects?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这可能是返回的子查询行的替代
,其中
person_id
为 null 表示行存在于person
中但不存在于group_membership
中I think this may be a substitute for the sub-query
Rows returned where the
person_id
is null indicate where rows exist inperson
but not ingroup_membership