Naveen
Naveen

Reputation: 111

sqlite: select all columns where one filed has max value over all columns

I have a table like this:

id int, col1 int, ...

Different rows can have col1 of same value. Now I want to gather all rows where col1 has a the maximum value. e.g. this table values

1 4
2 3
3 4

The query shall give my row 1 and 3

Upvotes: 1

Views: 593

Answers (1)

Lukasz Szozda
Lukasz Szozda

Reputation: 175606

You can use subquery:

SELECT id, col1
FROM tab
WHERE col1 = (SELECT MAX(col1) FROM tab);

SqlFiddleDemo

Upvotes: 1

Related Questions