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
Justin DJustin D 

Question on SOQL statement that has relationship between two tables

I am trying to write a SOQL statement that has a relationship between two tables.
The table "Survey__c" has a relationship with table "Student__c" at "StudentID__c"

The bottom query is what I am trying to mimic.
​SELECT Name, Phone, Account.Name FROM Contact

I have a bottom one so far, but I am not sure how to express correctly.
SELECT OtherUnique_ID, (Select SurveyChoice__c from Survey__r) FROM Student__c 

Can you please give me some feeback? Thanks in advance.
 
Malni Chandrasekaran 2Malni Chandrasekaran 2
Justin,
While fetching from child to parent, we use dot notation (as in the query you are trying to mimic). This works fine because any child record will have only one parent record.
While fetching from parent to chile, we use inner query ( as in ur existing query) this returns multiple child records for that particular parent record.
Unless 'Student__c' is a child object, you can not use dot notation in your query.

For more details, please refer,
https://developer.salesforce.com/blogs/developer-relations/2013/05/basic-soql-relationship-queries.html

Please mark it as Answer if it solves your problem