开发者

Can anyone explain to me this SOQL query?

I have one a SOQL query. Field list can i开发者_Go百科nclude 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?


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").


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜