Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

row with minimum value of a column

Tags:

sql

sql-server

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).

like image 846
mtz Avatar asked Oct 01 '10 14:10

mtz


People also ask

How do you find the minimum value in a row?

If the cells are in a contiguous row or columnSelect a cell below or to the right of the numbers for which you want to find the smallest number. , click Min (calculates the smallest) or Max (calculates the largest), and then press ENTER.

How do I select a row with minimum value in SQL?

To select data where a field has min value, you can use aggregate function min(). The syntax is as follows. SELECT *FROM yourTableName WHERE yourColumnName=(SELECT MIN(yourColumnName) FROM yourTableName);

How do you find the min of a column in a DataFrame?

Pandas DataFrame min() MethodThe min() method returns a Series with the minimum value of each column. By specifying the column axis ( axis='columns' ), the max() method searches column-wise and returns the minimum value for each row.

What is Loc and ILOC?

loc[] is used to select rows and columns by Names/Labels. iloc[] is used to select rows and columns by Integer Index/Position.


2 Answers

select * from TABLE_NAME order by COLUMN_NAME limit 1 
like image 191
Andrejs Cainikovs Avatar answered Oct 08 '22 15:10

Andrejs Cainikovs


I'd try this:

SELECT TOP 1 * FROM TABLE1 ORDER BY N_UM 

(using SQL Server)

like image 35
Adam V Avatar answered Oct 08 '22 17:10

Adam V