We need to use MAX(columnName) to find the maximum value in a column and MIN(columnName) to find the maximum value in a column.
Suppose the following is the syntax to find the highest and lowest value in a specific column -
mysql> SELECT @min_val:=MIN(columnName),@max_val:=MAX(columnName) FROM tableName; mysql> SELECT * FROM tableName WHERE columnName=@min_val OR columnName=@max_val;
Note: Suppose we have a database named "StudentsRecords" and a name The table for "STUDENT".
The following is our table
Student ID | Student ID | Student Score |
---|---|---|
90 | ||
97 | ||
72 |
Query
mysql> SELECT @min_val:=MIN(StudentMarks),@max_val:=MAX(StudentMarks) FROM STUDENT; mysql> SELECT * FROM STUDENT WHERE StudentMarks =@min_val OR StudentMarks =@max_val;
+---------------------+ | StudentMarks | +---------------------+ | 97 | +---------------------+
The above is the detailed content of Get minimum and maximum values in MySQL. For more information, please follow other related articles on the PHP Chinese website!