谁能向我解释一下这个 SOQL 查询吗?
我有一个 SOQL 查询。如果查询遍历关系,则字段列表可以包含子查询。例如:
SELECT Account.Name, (SELECT Contact.LastName FROM Account.Contacts) FROM Account
我无法理解“穿越关系”这句话,有人能解释一下吗?
I have one a SOQL query. Field list can include a subquery if the query traverses a relationship. For example:
SELECT Account.Name, (SELECT Contact.LastName FROM Account.Contacts) FROM Account
I couldn't understand the line 'traverses a relationship', can anyone explain it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我相信他们说您可以使用 SELECT 从与 FROM 子句中的表有关系的表中返回字段(如果它们有关系并且您使用子查询)。在您的示例中,您可以使用子查询从“Contact”表返回“LastName”,即使您的 FROM 是从“Account”中提取的,因为那里存在关系(“Account.Contacts”)。
I believe they're saying that you can use the SELECT to return fields from tables that have a relationship to the table in your FROM clause, if they have a relationship and you use a subquery. In your example, you are able to use the subquery to return "LastName" from the "Contact" table even though your FROM is pulling from "Account", because there is a relationship there ("Account.Contacts").
在这种情况下,这意味着您可以从“一”方对象的查询中从“多”方调用一对多关系。实际上,它类似于 SQL 中的嵌套查询,根据顶级查询中游标的当前位置来查询子表。差异主要在于 SQL 中的结果集是扁平的,而 SOQL 中的结果集是分层的。
更简单地说,这个查询的意思是:foreach Account 加载名称并遍历其所有联系人以检索联系人的姓氏。如果一个帐户有 10 个联系人,您将获得一个主行,并且其联系人列表将包含 10 行
In this instance it means you can recall a one to many relationship from the "many" side inside a query from the "one" side object. In effect it is similar to the nested query in SQL querying a subtable based on a current position of a cursor in top query. The difference is mostly in the result set begin flat in SQL versus being hierarchical in SOQL.
To make it even plainer, this query means: foreach Account load name and traverse all its contacts to retrieve contacts' last names. If there is one account with 10 contacts, you'll get one primary row and its Contacts list will contain 10 rows
不是有效的 sql。子查询应该有一个联接,否则它将返回多个记录,这将违反主查询每行一条记录的规则
not a valid sql. A subquery should have a join otherwise it will return more than one record this would violate the rule of one record per row of the main query