[SalesForce] Query parameter checking for related list size

Is it possible to check for a the size of a related list in a SOQL query? I am trying to find all Accounts that have no Contacts over the default Contact->Account Lookup.

Best Answer

This will give you all accounts with no Contacts

list<Account> accs = [Select Id, Name, yourOtherFields 
                      From Account 
                      Where Id Not In (Select AccountId from Contact)];
Related Topic