SQL MIN() Function

SQL MIN() function returns the smallest value from the selected column.

Syntax

SELECT MIN(columnName) FROM TableName

To understand MIN() function we will take example from [SalesPerson] table of AdventureWorks2012 database. We are selecting all rows from SalesPerson table.

MAX Function

For demonstration we will find minimum of SalesYTD from SalesPerson table.

SELECT MIN(SalesYTD) AS SalesYTD
FROM [Sales].[SalesPerson]

MIN Function

You can refer the output and compare from SalesYTD column in SalesPerson table as it is the minimum value from that column.

Similarly, we will take one more example from Bonus column as follows.

SELECT MIN(Bonus) AS MINBonus
FROM [Sales].[SalesPerson]

MINBonus

Note:

– Min() function ignores null values.

– For character columns, Min() function finds the lowest value from collating order i.e. from alphabets A-Z, it will return ‘A’ as minimum value.

Reference: Manzoor Siddiqui [www.SQLServerLog.com]

You may also like

You may also like...

Leave a Reply