How to query those Account which has not any related Contacts ? I have Queried Account and contact in inner query. I found All Account with that Account I looped and find those Account whose Contact equals Null. But I want, can it be acheive by query only no need to loop over Acccout . Please Help

1 Answer 1


This query will give you accounts that DO NOT have any contacts.

Select Id, Name From Account Where Id NOT IN (Select AccountId From Contact)

On the flip, you can query all Accounts that do have at least 1 contact like this

Select Id, Name From Account Where Id IN (Select AccountId From Contact)
  • No problem, glad to help :) Commented Aug 31, 2015 at 14:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .