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
GarrettzGarrettz 

SOQL V-LOOKUP

I'm looking for a similar feature in SOQL.

 

I have a child table where I want to take the value from a field (on each record in that table), and have it search for a matching value on a field from a parent table. The lookup field will most likely be blank.

 

If it finds a match, it will return selected field values from the parent table.

 

Here is a start at what I'm thinking, but quite possibly far off.

 

SELECT Id, fs_questionText__c, fn_order__c, fs_format__c, fs_questionId__c FROM t_questionType__c WHERE fs_questionId__c IN (SELECT fs_questionId__c FROM t_surveyResult__c)

 

**In this example, I am trying to pull the Id, the question text, the order, the format, and question ID from each record on the Question Type table that has a Question ID that is used in any record on the Survey Results table's Question ID field.**

 

Is that even possible? I'm afraid it isn't - I've seen some threads and ideas requesting this functionality.

 

-Garrett

AdrianCCAdrianCC

Hello @Garrettz! (btw you've reminded me of the Garrett PI series from Cook... gotta finish those) :)

 

You can't do the Select in Select thing. The idea is right, but the problem is you'll get an error cause the second select will return a List<t_surveyResult__c> and not a a List<String> which is needed for the IN.

 

You can first extract the fs_questionId__c and put them in a Set and then do the second soql.

List<t_surveyResult__c> surveysList= [SELECT fs_questionId__c FROM t_surveyResult__c];
Set<String> idsSet = new Set<String>();
for (t_surveyResult__c s: surveysList) {
    idsSet.add(s.fs_questionId__c);
}

List<t_questionType__c> typesList = [SELECT Id, fs_questionText__c, fn_order__c, fs_format__c, fs_questionId__c FROM t_questionType__c WHERE fs_questionId__c IN :idsSet];

 

Where are using this soql?

 

Have a nice day,

Adrian