可以进行复杂查询吗?
我有 3 个表,一个父表和 2 个子表。假设 Mother_c 是父母。那么Child_c和Pet_c是2个子表,它们具有指向Mother_c的主从关系指针。
我有 Child_c 中一行的 ID,我想从 Pet_c 中检索与该单个 Child_c 行的 Mother_c 相对应的所有行。
我想知道这是否可以在一个 SOQL 查询中实现?
I have 3 tables, a parent table and 2 child tables. Lets say Mother_c is the parent. Then Child_c and Pet_c are the 2 child tables that have master-detail relationship pointer to Mother_c.
I have the Id of one row from Child_c, I want to retrieve all the rows from Pet_c that correspond to the Mother_c of that single Child_c row.
I'm wondering if this is possible in one SOQL query?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,使用半连接 SOQL 完全可以实现这一点。我使用标准 CRM 对象对此进行了测试,如下所示:
为了引导您完成此操作,使用给定的联系人 ID,您首先找到父帐户,然后向下遍历到子案例。在带有自定义对象的示例中,它非常相似,但会使用 __r 自定义关系名称:
Yes, this is totally possible with semi-join SOQL. I tested this out with the standard CRM objects like this:
To walk you through this, with a given Contact id, you first find the parent Account, and then traverse back down to the child Cases. In your example with custom objects, it would be very similar, but would use the __r custom relationships names instead: