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
m@x~W0W~m@x~W0W~ 

SOQL

SELECT First_Name__c, Name From Student__c WHERE Class__r.Name IN (SELECT Class__r.Name FROM Teaches__c WHERE Subject__c IN ('Hindi','Maths'))

 

 

Doesn't works???

gautam_singhgautam_singh

Hi,

 

You are using inner query in where clause to get the list of ids but you are fetching the name. So , Nested Query doesnt work in this scenario.

 

I did this to achieve above:- 

List<Contact> myAccList = [ SELECT id,Name FROM Account WHERE Type IN('Prospects','Qualified')]; // You Inner Query Part
if(myAccList.size()>0){
List<Contact> Con = [SELECT id , FirstName , LastName FROM Contact WHERE ID =: myAcclist.id ]; // You External Query Part , I havent tested this in DEVELOPER CONSOLE, mite me wrong over Syntax
}

 

Important :

Click on the Star Icon aside if this post provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

Thank You

sandeep@Salesforcesandeep@Salesforce

You should create a list sepearately : -

List<String> Listofsubjects = new List<String>{'Hindi', 'Maths' };

 

SELECT First_Name__c, Name From Student__c WHERE Class__r.Name IN (SELECT Class__r.Name FROM Teaches__c WHERE Subject__c IN: Listofsubjects ))