Thursday, November 2, 2017

Using MAX and MIN Functions

Beside Average, Count and Sum functions, SQL statement also have MIN and MAX functions.
MIN function returns the data with the minimum value in a column. This to obtain the minimum value in a column is:
Figure 1 below shows how the above SQL statement is used to obtain the smallest year number in the table students.
Figure 1: Output the minimum year number from table students using the SQL MIN function.
MIN Function outputted the minimum value in the column, Then MAX function will output the maximum value from the particular column for SQL statement. The syntax for MAX function in SQL statement is:
Figure 2 below shows the SQL statement obtain the largest (Maximum value) student ID in the table students using MAX function.
Figure 2: Output the largest (Maximum Value) student ID in table students