Cam someone please convert the below SQL query to SOQL?

enter image description here


Select id, Name, product_code, (select product_code from product b where b.parent_id=a. id) as parent_code from product a

How to get these results through in salesforce/SOQL?


  • 2
    What have you tried so far? It'll be more valuable for you if you work through this instead of someone just giving you the answer outright. – Derek F Jan 24 '18 at 18:11
  • I am new to SOQL, I tried and finally posted here. You can simply Ignore !!! – mani Jan 26 '18 at 17:35

You're trying to do a Left Outer Join.

First step is to find the child relationship name. If you have a custom lookup, it's going to end in __r and it's usually plural. So for example if it were Products__r, you would do:

SELECT (SELECT Product_Code__c FROM Products__r) FROM Parent_Object__c
  • your query returns product code of a child record. Parent 1| ch1 , I want the code for parent i.e Child1 | pr1 – mani Jan 26 '18 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.