1

I need a count of Contacts that are associated with Accounts that have ever had an Opportunity. Here's the query as I think it should be

SELECT count() FROM Contact WHERE AccountID in 
    (SELECT id FROM Account WHERE AccountID in
          (SELECT AccountId FROM Opportunity)
    )

I get a malformed query error: Nesting of semi join sub-selects is not supported

My googling tells me I need to break this up into two queries, but I need to do this in Workbench for "reasons". Am I out of luck?

1 Answer 1

2

Here is a straightforward solution:

SELECT COUNT() FROM Contact 
   WHERE AccountId IN (SELECT AccountID FROM Opportunity)

Find all Contacts whose AccountId exists in any Opportunity. This presumes your Opportunities all have AccountId populated. It is technically not a required field per the Object Reference

So, to be more precise:

SELECT COUNT() FROM Contact 
   WHERE AccountId IN (SELECT AccountID FROM Opportunity WHERE AccountId != NULL)
1
  • Shocking no one I was overcomplicating things!!! Thank you!!! Mar 11, 2021 at 18:51

You must log in to answer this question.

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