function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Nurav1982Nurav1982 

Quick Question on Aggregate SOQL queries

Hello All,

 

This is the data setup in object Child__c

 

http://imgur.com/50arUIy,AO95lex#0

 

 

 

This is what I wanted to achieve :

 

http://imgur.com/50arUIy,AO95lex#1

 

 

As you can see I am able to achieve my desired output (Grouping based on parent__r.id) using the above query.

 

But I am not able to understand the role played  "id" inside count().

 

What did "id" inside the count() operator do ?.

 

The same setup in a traditional SQL is straightforward as below.

 

SELECT Parent__r.id,count(*)

FROM Child__c

GROUP BY Parent__r.id

ORDER BY count(*) DESC

 

So can someone explain the role played "id" inside the SOQL statement ?

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Subhash GarhwalSubhash Garhwal
Hi Nurav,
if you use id in count() operator than it count all the the child records under parent id, by using id in count() no record will count twice, so it show expect count.

All Answers

Subhash GarhwalSubhash Garhwal
Hi Nurav,
if you use id in count() operator than it count all the the child records under parent id, by using id in count() no record will count twice, so it show expect count.
This was selected as the best answer
Nurav1982Nurav1982
TX :)