function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MPS DevMPS Dev 

Nested query

Hello, 
I have 2 custom objects and 1 standard(Project, Task, Assignment). Each Project can have multiple tasks, Each Task has 1 Assignment.
I can query it like this 

SELECT Assignment.Name FROM Task WHERE WhatId = 'RecordId'
I thought it might be cool to do something like this
SELECT ( SELECT (SELECT Name FROM Assignment) FROM Task) FROM Project
BUT I can't seem to get the second query to compile, any insight would be appericiated!
v varaprasadv varaprasad
Hi Michael,

try once like below : 
 
Each assignment task and project details : 

SELECT Name,Task.id,Task.Project__r.name FROM Assignment

Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.

Thanks
Varaprasad
@For  Support: varaprasad4sfdc@gmail.com
Blog : http://salesforceprasad.blogspot.com/
 
v varaprasadv varaprasad
SELECT id,(SELECT Name FROM Assignments),Project_r.name FROM Task

3rd way : 

list<Project> projects = [SELECT id,( SELECT id FROM Tasks) FROM Project];
set<id> tskIds = new set<id>();

for(Project pt : projects){
    if(pt.tasks.size()>0){
	  for(task t : pt.tasks){
	    tskIds.add(t.id);
	  
	  }
	
	
	}

}


list<Assignment>   asignments= [SELECT Name FROM Assignment where taskid in : tskIds];

 
Ajay K DubediAjay K Dubedi
Hi Michael,

Please see the below link :

http://blog.jeffdouglas.com/2010/02/22/soql-how-i-query-with-thee-let-me-count-the-ways/   
 
It has sufficient information.

Please mark as best answer if it helps you.

Thank You 
Ajay Dubedi