1.

How To Write The “where” Clause In Soql When Group By Is Used?

Answer»

We cannot USE the “Where” clause with Group By INSTEAD we will need to use the “Having Clause“.

Example: 

Get all the opportunity where more than one record EXISTS with same name and name contains “ABC”.

SELECT COUNT(ID) , Name FROM Opportunity GROUP BY Name Having COUNT(Id) > 1 AND Name LIKE '%ABC%'

We cannot use the “Where” clause with Group By instead we will need to use the “Having Clause“.

Example: 

Get all the opportunity where more than one record exists with same name and name contains “ABC”.

SELECT COUNT(Id) , Name FROM Opportunity GROUP BY Name Having COUNT(Id) > 1 AND Name like '%ABC%'



Discussion

No Comment Found