Skip to content
Related Articles

Related Articles

Improve Article

MIN() Function in SQL Server

  • Last Updated : 21 Jan, 2021

MIN() :

This function in SQL Server is used to find the value that is minimum in the group of values stated.

Features :

  • This function is used to find the minimum value.
  • This function comes under Numeric Functions.
  • This function accepts only one parameter namely expression.

Syntax :

MIN(expression)

Parameter :



This method accepts one parameter.

  • expression – 
    A specified numerical value which can either be a field or a given formula.

Returns :

It returns the value that is minimum in the group of values stated.

Example-1 :

Using MIN() function and getting the output.

CREATE TABLE product
(  
user_id int IDENTITY(100, 2) NOT NULL,    
product_1 VARCHAR(10),
product_2 VARCHAR(10),
price int  
);
INSERT product(product_1, price)  
VALUES ('rice', 400);

INSERT product(product_2, price)  
VALUES ('grains', 600);

SELECT MIN(price) FROM product;

Output :

400

Example-2 :

Using MIN() function and finding the minimum value of the stated float values.



CREATE TABLE floats
(  
user_id int IDENTITY(100, 2) NOT NULL,
float_val float
);
INSERT floats(float_val)  
VALUES (3.5);

INSERT floats(float_val)  
VALUES (2.1);

INSERT floats(float_val)  
VALUES (6.3);

INSERT floats(float_val)  
VALUES (9.0);

INSERT floats(float_val)  
VALUES (7.0);

SELECT MIN(float_val) FROM floats;

Output :

2

Example-3 :

Using MIN() function and getting the output where MRP is greater than the minimum of all the MRP’s.

CREATE TABLE package
(  
user_id int IDENTITY(100, 4) NOT NULL,  
item VARCHAR(10),
mrp int  
);
INSERT package(item, mrp)  
VALUES ('book1', 3);

INSERT package(item, mrp)  
VALUES ('book2', 350);

INSERT package(item, mrp)  
VALUES ('book3', 400);

SELECT * FROM package
WHERE mrp > (SELECT MIN(mrp) FROM package);

Output :

  | user_id  | item     | mrp
--------------------------------
1 | 100      | book2    | 350
--------------------------------
2 | 104      | book3    | 400

Example-4 :

Using MIN() function and getting the minimum value of all the (MRP-sales price) values.

CREATE TABLE package
(  
user_id int IDENTITY(100, 4) NOT NULL,  
item VARCHAR(10),
mrp int,
sp int
);
INSERT package(item, mrp, sp)  
VALUES ('book1', 250, 240);

INSERT package(item, mrp, sp)  
VALUES ('book2', 350, 320);

INSERT package(item, mrp, sp)  
VALUES ('book3', 400, 350);

SELECT MIN(mrp-sp) FROM package;

Output :

10

Application :

This function is used to find the minimum value of all the values stated.

My Personal Notes arrow_drop_up
Recommended Articles
Page :