Roman
Roman

Reputation: 175

SQL - only display rows that have the max value

I have this table that is already sorted but I want it to only display the maximum values... so instead of this table:

+------+-------+
| id   | value | 
+------+-------+
| 1    |  3    | 
| 5    |  3    |
| 4    |  3    |
| 9    |  2    | 
| 8    |  2    |
| 3    |  2    |
| 2    |  1    |
| 6    |  1    |
| 7    |  1    |
+------+-------+

I want this:

+------+-------+
| id   | value | 
+------+-------+
| 1    |  3    | 
| 5    |  3    |
| 4    |  3    |
+------+-------+

I'm using SQLite. thanks for any help.

Upvotes: 0

Views: 42

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269445

You can do this using a subquery. Here is one way:

select t.*
from t
where t.value = (select max(value) from t);

Upvotes: 2

Related Questions