0

Cam someone please convert the below SQL query to SOQL?

enter image description here

SQL:

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?

Thanks

2
  • 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
    Commented Jan 24, 2018 at 18:11
  • I am new to SOQL, I tried and finally posted here. You can simply Ignore !!!
    – mani
    Commented Jan 26, 2018 at 17:35

1 Answer 1

4

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
1
  • your query returns product code of a child record. Parent 1| ch1 , I want the code for parent i.e Child1 | pr1
    – mani
    Commented Jan 26, 2018 at 17:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .