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

Need help with SOQL - relationships

I need to write a SOQL that can return the following result.
I have two objects Account and Cards. Cards has a lookup field to the Account object, but it is not in Parent-Child relationship.
I need to get a list of All account names that has atleast one record in the Cards Object. I cannot create a summary field due to other constriants.
Any feedback on this is greatly appreciated. Thanks

You can use following SOQL


Select [Cards look up field name]__r.Name from Account where [Cards look up field name]__c <>null


Thanks and regards,



Hi Jagannath,

Thanks for the response. I think what you meant is as follows:

Select [Cards look up field name]__r.Name from Cards where [Cards look up field name]__c <>null

I tried this SQL but then I get a lot of duplicates since for one account, there are many cards so its like a one-to-many relationship.

How can I remove the duplicates since "DISTINCT" does not work in SOQL?




Michael SnowMichael Snow
I may not be doing this in the most efficient way possible, but you could try:
Select Name, (Select Id from Cards) From Account
and then only look at where > 0 and ignore the other account records.
That's the only way to do it right now.