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
Hardik Baldania 4Hardik Baldania 4 

Querying 2 unrelated custom objects in a single query.

Hello, 

I have a situation in which I have to run a single query from 2 differenct unrelated custom objects and I actually have no clue how to do that in SOQL, as SOQL doesn't have the JOIN functionality. 

I have 2 Custom Object named: 1. jud_city_list__c and 2. jud_dlr_list__c. 
This is the SQL query which I want to access through SOQL.

SELECT `l`.`city`, `l`.`pref_dlr1`, `l`.`pref_dlr2`, `l`.`pref_dlr3`, `d`.`name`, `d`.`dlrid`, `d`.`state` 
AS `dlr_states`, `d`.`city` AS `dlr_city`, `d`.`ud_dlrid`
FROM `jud_city_list` `l`JOIN `jud_dlr_list` `d` ON `d`.`dlrid` IN (l.pref_dlr1,l.pref_dlr2,l.pref_dlr3)
WHERE `l`.`city` LIKE 'm%' ESCAPE '!'ORDER BY `l`.`city` ASC

where l - jub_city_list__c object
          d - jub_dlr_list__c object. 

I don't know how to get this SQL query into SOQL query. Do I have to write a wrapper class for this ? Or Is there any other possible way available to get this query written into SOQL ?

Thanks you so much in advance, looking for some serious help.

Regards,
Hardik B.
Saurabh Gupta ManrasSaurabh Gupta Manras
Dear, Querying 2 unrelated custom objects in a single query is not possible .we cannot do join operations in soql, you will have to split this query into two and perform actions accordingly. Do let me know if you need any further help.
Please choose it as the Best answer, if you find it helpful .
 
Hardik Baldania 4Hardik Baldania 4
Dear, I know that we can't join two query into one. But is there any other way around to get two query into one single query ? 
Arpit Jain7Arpit Jain7
Hi Hardik,

May be you can query both object seperately by using 2 lists and then use wrapper to put both unrelated objects data in single list.

Thanks
Arpit
 
Hardik Baldania 4Hardik Baldania 4
But, My major issue is, I want to get the output from 2 unrelated objects n fields if have both similar value in it showing as one single  output not as 2 different output.