MIN() and MAX() functions in SQL

Sql MIN() function is to get the minimum number from a column. And, MAX() function is used to display maximum number from a table’s column. Examples are given below-

Database Namejai_school

CREATE DATABASE jai_school;

Create a tableresult

CREATE TABLE result(students VARCHAR(50),marks INT(10));

Insert data in result table

INSERT INTO result(students,marks)VALUES("Ram",450);
INSERT INTO result(students,marks)VALUES("Rahim",200);
INSERT INTO result(students,marks)VALUES("Shyam",90);
INSERT INTO result(students,marks)VALUES("Anita",350);
INSERT INTO result(students,marks)VALUES("Raman",200);
INSERT INTO result(students,marks)VALUES("Nobita",70);
INSERT INTO result(students,marks)VALUES("Ravi",250);
INSERT INTO result(students,marks)VALUES("Aman",150);
INSERT INTO result(students,marks)VALUES("Ravina",500);

Table Image-

table-for-MIN-and-MAX

SQL MIN() function

SELECT MIN(marks) FROM result;

query result-

sql-MIN-example

Display MIN(marks) in another column

SELECT MIN(marks) AS min_marks FROM result;

query result-

sql-MIN-with-AS

SQL MAX() function

SELECT MAX(marks) FROM result;

query result-

sql-MAX

Display MAX(marks) in another column

SELECT MAX(marks) AS max_marks FROM result;

query result-

sql-MAX-with-AS

Leave a Comment