In SQL, how can I select the minimum value of a column a
(integer) where the column b
(integer) is the maximum value for that column, using only one select ?
SELECT MIN(a) OVER (PARTITION BY MAX(b)) as res #seems to be ill-formed
FROM table
For instance
a | b |
---|---|
1 | 1 |
1 | 3 |
2 | 3 |
should return
res |
---|
1 |
3
Answers
order by
andlimit
should be good enough here:You can do it with a nested SELECT MIN
Using windowing functions to avoid a second pass on the table: