You need to sign in to do that
Don't have an account?
How can I get all records with only max "Version__c" in query statement return?
Example: I have a Object A with many fields: ID, Name, Version__c,DescriptionName__c
and Data here:
Record : Name Version__c DescriptionName__c
Protocol1 1 //
Protocol1 2 //
Protcol 2 1 //
Protocol3 1 //
Protocol2 2 //
I want to get All Protocols have max value.
The result have to return : Protocol1 - version :2
Protocol2- version: 2
Protocol3 - version:1
Please help me,
datthepsoft
LIST<AggregateResult> maxVer = new LIST<AggregateResult> ();
maxVer = [SELECT MAX(Version__c),name mxVr FROM ObjectA__c GROUP BY Name ];
for(AggregateResult sobj : maxVer){
String maxVersion = Integer.valueOf(sobj.get('name')) + Integer.valueOf(sobj.get('mxVr'));
}
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
Thank you for your help! But I want to make query string dont have code behide. :D
Could you please help me?
So your query string will be like this
LIST<AggregateResult> maxVer = new LIST<AggregateResult> ();
String soqlQuery = 'SELECT MAX(Version__c),name mxVr FROM ObjectA__c GROUP BY Name';
maxVer = Database.query(soqlQuery);
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
Try the following query:
SELECT Name, DescriptionName__c, MAX(Version__c)
FROM OBJECT_NAME WHERE Version__c !=NULL
GROUP BY Name
Let me know if it suits your requirement or needs change
I can not get result with:
'Select ID,DescriptionName__c, Max(Version__c), name mxVr From ObjectA__c Group By Name'.
and see error:
I want to get all field in Object. Could you please help me!
Thanks,
Like the error message says, you have to group the fields that are not aggregated.
Add these fields to the grouping.