...

Database Managment - MySql

Back to Course

Lesson Description


Lession - #1310 SQL MinMax


The MIN(>
function returns the smallest value of the selected column.
The MAX(>
function returns the largest value of the chose column.

Syntax



#MIN(>
Syntax SELECT MIN(column_name>
FROM table_name WHERE condition; #MAX(>
Syntax SELECT MAX(column_name>
FROM table_name WHERE condition;


Let's see an example



-- create
CREATE TABLE EMPLOYEE (
  empId INTEGER PRIMARY KEY,
  name TEXT NOT NULL,
  dept TEXT NOT NULL,
  salary INTEGER
>
; -- insert INSERT INTO EMPLOYEE VALUES (0001, 'Clark', 'Sales',4567>
; INSERT INTO EMPLOYEE VALUES (0002, 'Dave', 'Accounting',6000>
; INSERT INTO EMPLOYEE VALUES (0003, 'Ava', 'Sales',7690>
; -- fetch SELECT MIN(salary>
AS lowsal FROM EMPLOYEE ; SELECT max(salary>
AS highsal FROM EMPLOYEE ;

Output


Try it here