Quantcast
Channel: Optimising some SQL to get all rows corresponding to the minimum value of a column - Database Administrators Stack Exchange
Viewing all articles
Browse latest Browse all 2

Optimising some SQL to get all rows corresponding to the minimum value of a column

0
0

I've worked out how to get some rows from a table where a column has the lowest possible value. Note this can return multiple rows, which is what I want. It works just fine.

SELECT col1, col2FROM TableAWHERE col4=0    AND col5=1    AND col3 IN       (SELECT MIN(col3)        FROM TableA        WHERE col4=0 AND col5=1)

But is the nested select overkill, i.e. can this be optimised? Maybe there's a simple SQL command I'm missing...

I tried

SELECT col1, col2, MIN(col3)FROM TableAWHERE col4=0    AND col5=1

but this will only ever return one row.


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images