0

Not too sure how to explain it very well in the title.

To note: I'm using PHP and PDO for querying the sql database.

I have a table with a list of numbers that are not unique, and a 2nd column with a number that I only want the highest of - and only if the highest of them is above 50, example:

0 - 50
0 - 80
1 - 24
1 - 88
2 - 11
2 - 44

From the above, I would only want 0 - 80 and 1 - 88 returned, what is a good way of achieving this?

I can only think of an inefficient method which returns all rows and then compares one by one adding values to an array and replacing them if a higher one exists in a loop.

Sakuya
  • 660
  • 5
  • 23

1 Answers1

1

Check:

SELECT DISTINCT col1, MAX(col2) maximus
FROM my_table 
GROUP BY col1
HAVING maximus > 50