You need to sign in to do that
Don't have an account?

Nested Queries in soql
Hi,
i'm new to apex. I need help in writing nested Query in soql.
I need the following nested query in SOQL form. IS it possible write in this way?Then how to write it in SOQL.
please help me
the query is written in sql form:
select emailid from userprofile where empname in (select deptHead from department where deptId in (select deptId from Userprofile where empId='1001'));
-Shravan
Please see this link. http://blog.jeffdouglas.com/2010/02/22/soql-how-i-query-with-thee-let-me-count-the-ways/
It has sufficient information.
Thanks,
Naresh
All Answers
Please see this link. http://blog.jeffdouglas.com/2010/02/22/soql-how-i-query-with-thee-let-me-count-the-ways/
It has sufficient information.
Thanks,
Naresh
You can do one level of nested query at like below
List<Contact> contacts = [select id from Contact c where c.AccountId in (select id from Account ) ];
but if you add one more level like
List<Contact> contacts = [select id from Contact c where c.AccountId in (select id from Account where createdby in (select id from User) ];
it gives error
Thanks for sharing that link!
Hi ,
So dharmesh is it not possible to do three level nested query in SOQL.
i'm still having the difficulty in doing this query
thanks to all...
Yes the third level sub query will give error.
Hello,
The link below explain nested queries with simplest example, you would understand the concept and apply to your business requirement.
https://www.sfdc99.com/2013/06/24/example-how-to-write-a-cross-object-soql-query-part-2/