1

Can an aggregate function be in SOQL where clause? Looks like it cannot but I can't find anywhere a documentation a clear answer if it is forbidden and why if it is

1
  • The more details you provide, particularly code you've written to provide an example of what you're asking, the more likely it is that someone will respond to your question with an answer you'll find helpful.
    – crmprogdev
    Commented Sep 8, 2015 at 18:11

1 Answer 1

2

Look at the documentation around the HAVING clause.

Example:

SELECT Account.Owner.Name
FROM Opportunity
GROUP BY Account.Owner.Name
HAVING COUNT(Id) > 100
3
  • Yes, I know about Having, I wonder why we can't just query SELECT Account.Owner.Name FROM Opportunity where COUNT(Id) > 100 Commented Sep 8, 2015 at 19:05
  • 1
    @XpucTuHKaBuwuBaHKa HAVING applies to "groups" of rows, while WHERE applies to "individual" rows. This is how standard SQL works, and SOQL is a subset of this.
    – sfdcfox
    Commented Sep 8, 2015 at 19:24
  • This is one of the really obscure questions that can absolutely nail someone taking a certification exam when they've never run across a situation where they needed to create a query like the one above.
    – crmprogdev
    Commented Sep 8, 2015 at 22:51

You must log in to answer this question.

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