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-
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'.
Syntax-
SELECT MAX(COLUMN_NAME) FROM TABLE_NAME
Example-
Let we have a table 'tblStudents' which have the following data as shown below-
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