Skip to main content
How to query all rows that have the highest value in a specific column? Or how to filter by the max value that's in a specific column? Or how to count the number of rows that have the highest value in a specific column, then use that count in the LIMIT clause?

 

I'm able to get that highest value using the MAX function shown below, but so far not able to apply it to my main query below to return specific fields from only those rows with that MAX value. There are multiple rows with that MAX value.

 

I hope these faxsimile queries explain sufficiently what I'm doing. Have tried about 100 different configurations.

 

Right now my main query is returning all rows with that ID, where I need it to return only the rows with the highest value in the 'Name' field.

 

Thank you.

SELECT FieldA, FieldB, Name FROM Object WHERE ID = '123' ORDER BY Name DESC

SELECT MAX(Name) FROM Object WHERE ID = '123'

3 respostas
  1. 28 de fev. de 2021, 21:40
    Hi Lynda,

     

    Yes,use List variable in Apex.