'How to get max values for each unique value in a different column in Google Sheets?

I have two columns, the first column (A) has names and the second column (B) has values.

A B
apple 10
orange 12
orange 14
apple 8

Is there a way to get only rows with unique names from A AND max values from B? So the result should look like this:

A B
apple 10
orange 14

I tried using different combinations of FILTER, QUERY and UNIQUE, but so far no luck. Note that the actual dataset I'm using is much larger than this, but the idea is the same.



Solution 1:[1]

use:

=SORTN(SORT(A:B; 2; 0); 9^9; 2; 1; 1)

Solution 2:[2]

Should be doable directly within a query as well:

=query(A:B,"select A,max(B) where A is not null group by A")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 player0
Solution 2 The God of Biscuits