Sunday, April 16, 2017

MIN() in SQL Server


SQL MIN() function is used to return the minimum of all values in a column. The MIN() can only be applied on ANY type of column.  For character columns, MIN finds the lowest value in the collating sequence. The MIN() determines the minimum of all the non-NULL values in the columns, NULL values are ignored.

Syntax:

     
            SELECT MIN(ALL | DISTINCT column_name) FROM table_name


column_name is the name of the column of which total occurrences is to be calculated.

table_name is the name of the table


Example 1:
MIN() on numeric column.

SELECT * FROM TempEmployeePayHistory




SELECT MIN(Rate) FROM TempEmployeePayHistory



Example 2:
MIN() on date column.

          SELECT * FROM DatabaseLog




SELECT MIN(PostTime) FROM DatabaseLog



Example 3:
MIN() on text column.

          SELECT MIN([Event]) FROM DatabaseLog




Example 4:
MIN() with GROUP BY clause.

SELECT Event, MIN(PostTime) FROM DatabaseLog GROUP BY [Event]




Share This
Previous Post
Next Post

TekGrabs, established in 2017, is in the business of sharing Information. It provides news, articles and photos about the different technologies, inventions in different domains. Provides information on programming and databases.

0 comments: