row with minimum value of a column

Viewed 75273

Having this selection:

id IDSLOT  N_UM
------------------------
1  1  6
2  6  2
3  2  1
4  4  1
5  5  1
6  8  1
7  3  1
8  7  1
9  9  1
10  10  0

I would like to get the row (only one) which has the minimun value of N_UM, in this case the row with id=10 (10 0).

7 Answers

Method 1:

SELECT top 1 * 
FROM table 
WHERE N_UM = (SELECT min(N_UM) FROM table);

Method 2:

SELECT * 
FROM table 
ORDER BY N_UM 
LIMIT 1

A more general solution to this class of problem is as follows.

Method 3:

SELECT *
FROM table 
WHERE N_UM IN (SELECT MIN(N_UM) FROM table);
Related