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
Irina Khomyakova 38Irina Khomyakova 38 

Help with SOQL query using parent-child relationships

I am trying to build SOQL query displaying credit summary for a particular student. We're on EDA so we're trying to use the Course, Course Offering, Course Connection, and Contact objects to generate this. 
Here is query that displays information we need, but only for courses particular student enrolled. We would need to add course information for courses that student is not enrolled.

select (SELECT hed__Course_Offering__r.hed__Course__r.Subject__c,
hed__Course_Offering__r.hed__Course__r.Catalog_Number__c,
hed__Course_Offering__r.hed__Course__r.Name,
hed__Course_Offering__r.hed__Course__r.hed__Credit_Hours__c, hed__Course_Offering__r.hed__Course__r.Course_Name_in_Native_Language__c,
Letter_Grade__c
FROM hed__Student_Course_Enrollments__r where Subject__c ='GDBA' and Catalog_Number__c LIKE '71%')  
from Contact where Id='0031I00001NcWIBQA3'

I also tried this query, but information is not distinct and not properly formatted:

SELECT  hed__Course__r.Subject__c,
hed__Course__r.Catalog_Number__c,hed__Course__r.Name, hed__Course__r.hed__Credit_Hours__c,
hed__Course__r.Course_Name_in_Native_Language__c,
(Select Letter_Grade__c  from hed__Course_Enrollment__r where hed__Contact__c = '0031I00001NcWIBQA3')
FROM hed__Course_Offering__c Where hed__Course__r.Subject__c ='GDBA' and hed__Course__r.Catalog_Number__c LIKE '71%'

I would appreciate any suggestions.
Suraj Tripathi 47Suraj Tripathi 47
Hi Irina,

Check this SQL query:-
select (SELECT hed__Course_Offering__r.hed__Course__r.Subject__c,
hed__Course_Offering__r.hed__Course__r.Catalog_Number__c,
hed__Course_Offering__r.hed__Course__r.Name,
hed__Course_Offering__r.hed__Course__r.hed__Credit_Hours__c, hed__Course_Offering__r.hed__Course__r.Course_Name_in_Native_Language__c,
Letter_Grade__c
FROM hed__Student_Course_Enrollments__r where hed__Course_Offering__r.hed__Course__r.Subject__c = 'GDBA' and hed__Course_Offering__r.hed__Course__r.Catalog_Number__c LIKE '71%')  
from Contact where Id='0031I00001NcWIBQA3'
In case you find any other issue please mention. 
If you find your Solution then mark this as the best answer. 
Irina Khomyakova 38Irina Khomyakova 38
Hi Suraj,  Thank you very much for query you provided.  It shows exactly the same results as my first query.  I would like to show also course data for courses that students were not enrolled, so there is no student course enrollment record.  Is there a way to build it all in one single query?