Improve your skills

July 22, 2016

Get Maximum Value of a Column in SQL Server

The MAX() function is return the maximum value of a column in sql server.

Syntax- 
SELECT MAX(COLUMN_NAME) FROM TABLE_NAME

Example-
Let we have a table 'tblStudents' which have the following data as shown below-


get-max-value-of-a-column-in-sql-server













Now we use MAX() function to get maximum marks from table.

SELECT ISNULL(MAX(marks), 0) max_marks FROM tblStudents 

Result-












Note- 
If our table have no records then it returns 'NULL'. To avoid this problem we use ISNULL() function, then it returns the '0' in place of 'NULL'.



0 comments:

Post a Comment

Subscribe for Latest Update

Popular Posts