You need to sign in to do that
Don't have an account?

Need help with SOQL - relationships
Hi,
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
Ambili
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,
Jagannath
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?
Thanks,
Ambili
Select Name, (Select Id from Cards) From Account
and then only look at account.name where account.cards.length > 0 and ignore the other account records.