-3

We are querying max value among certain field values of same data type from an object. we cant form perfect query . could anyone help to get perfect query.

2
  • It'd be easier to answer if you can share your current query and what output you'd like. Adding more details and context in your question will help us help you! :) Commented Jun 2, 2014 at 13:57
  • Oppty= [select MAAmount), AccountID from Opportunity where AccountID=:Acc.Id group By AccountID]; HI this is the query we have used . Our scenario is to get the max value among the set of field's. Commented Jun 2, 2014 at 15:28

1 Answer 1

6

I would look into Aggregate Results queries. Without knowing too much about your requirements , here is a simple example below

list<aggregateResult> aggResults = [SELECT MAX(Amount)myMax FROM Opportunity];
System.debug('Max is: ' + aggResults[0].get('myMax'));

For more on AggregateResult queries, see the links below

http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_SOQL_agg_fns.htm

http://blog.jeffdouglas.com/2010/04/12/using-aggregateresult-in-salesforce-com-soql/

Not the answer you're looking for? Browse other questions tagged .