+ Start a Discussion
praveen venkatapraveen venkata 

How many inner Queries for sub queries in a query can be written?

Like:

 

list<library__c> lib_list=[select ID,Name,fee__c,(select ID,Name,type__c,(select ID,name,phone__c from student__r) from sports__r) from library__c];

 

 

Can it be possible?

Vinita_SFDCVinita_SFDC

Hello,

Following are the limitations:

   1. Relationship queries are not the same as SQL joins. You must have a relationship between objects to create a join in SOQL.
   2. No more than 35 child-to-parent relationships can be specified in a query. A custom object allows up to 25 relationships, so you can reference all the child-to-parent relationships for a custom object in one query.
  3.  No more than 20 parent-to-child relationships can be specified in a query.
   4. In each specified relationship, no more than five levels can be specified in a child-to-parent relationship. For example, Contact.Account.Owner.FirstName (three levels).
    5.In each specified relationship, only one level of parent-to-child relationship can be specified in a query. For example, if the FROM clause specifies Account, the SELECT clause can only specify the Contact or other objects at that level. It could not specify a child object of Contact.

For further reference: http://www.salesforce.com/us/developer/docs/dbcom_soql_sosl/Content/sforce_api_calls_soql_relationships.htm