0

Can any one let me know if "GROUP BY" can be used in a relationship query.

In the given Query, I'm using "GROUP BY" to identify the same product name in a relationship.

SELECT gmod__product__r.name, Sum(gmod__Amount__c) gmod__Amount__c, Sum(gmod__Quantity__c) gmod__Qunatity__c, COUNT(id) Quantity
FROM gmod__Opportunity_Forecast__c GROUP BY gmod__product__r.name

Any help is very much appreciated

  • 1
    What issue did you face with the query? Are you getting any compilation error or not getting the data you need? – singularity Feb 24 '15 at 19:01
  • @ singularity:When i use the Query it works fine in the Developer console.But when i use in the controller it does not displays the data. – nikkey Feb 25 '15 at 8:49
3

Group by can be used with relationship queries. For ex., following query works and returns the appropriate data.

select account.name, count(id) from contact group by account.name limit 100
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.