You need to sign in to do that
Don't have an account?
vhanson222
SOQL Relationship query question
Is it possible to limit a query to only return records with subrecords? For example, I want to find all Accounts that have at least one Note record associated with them.
IE:
List<Account> accountsWithContacts = [SELECT Name, Id, (SELECT Id FROM Notes) FROM Account WHERE Notes.size > 1];
obviously the above example code is invalid, but essentially that is what I would like to accomplish.
any advice is greatly appreciated -- this seems like something that should be able to be accomplished via SOQL instead of having to return all accounts and sort them out after the query.
Something like this?
Account[] a = [Select ID, Name, (Select ID From Contacts) From Account where ID IN (Select AccountID From Contact)];
All Answers
Something like this?
Account[] a = [Select ID, Name, (Select ID From Contacts) From Account where ID IN (Select AccountID From Contact)];
That did the trick. Thanks!