+ Start a Discussion
Satish InugantiSatish Inuganti 

EXCLUDE A VALUE IN GROUP BY

Hello Team,

I have a below query which is returning " MALFORMED_QUERY: Field must be grouped or aggregated: Rate__c " This error in workbench. However i cannot exclude this field since i need in rest of the class and also this cannot be grouped.

Can anyone suggest me a workaround how we can exclude a value in GROUP BY Clause. Any Ideas plss ?

Query:
SELECT Right_Hand_Currency__c,Rate__c,Max(Date__c) FROM Exchange_Rate__c WHERE  Left_Hand_Currency__c = 'HKD' AND Type__c = 'SELLING' AND Country_Data__c = 'HK' AND Right_Hand_Currency__c IN ('AUD', 'EUR', 'USD', 'CAD', 'GBP', 'NZD', 'CHF', 'HKD','MOP') GROUP BY Right_Hand_Currency__c

User-added image
karthikeyan perumalkarthikeyan perumal
Hello satish

try below query, 
 
SELECT Right_Hand_Currency__c,Rate__c,Max(Date__c) FROM Exchange_Rate__c WHERE  Left_Hand_Currency__c = 'HKD' AND Type__c = 'SELLING' AND Country_Data__c = 'HK' AND Right_Hand_Currency__c IN ('AUD', 'EUR', 'USD', 'CAD', 'GBP', 'NZD', 'CHF', 'HKD','MOP') GROUP BY Right_Hand_Currency__c,Rate__c

hope this works for you. 

Thanks 
​​​​​​​karthik
 
Satish InugantiSatish Inuganti
Hi Karthik,

Rate__c cannot be grouped since this field will have many abstract values. So is there any possibility to exclude this value by using any other clause ?

Thanks,
Satish.
karthikeyan perumalkarthikeyan perumal
Hello satish, 

sorry i dont think so any other possibility to excute.  but in SOQL select fields need to be grouped by. if you dont want to add Rate__c in group by you need to remove that from select and if you want add Rate__c in select  while using aggregated function you need to add all fiedls in group by . 

Thanks
karthik