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.
Similar Reads
PI() Function in SQL Server
PI() function : This function in SQL Server is used to return the constant float value of math Pi. The default number of decimal places displayed is seven, but SQL Server uses the full double-precision value internally. Features : This function is used to get the value of pi.This function does not a
1 min read
MONTH() Function in SQL Server
MONTH() function : This function in SQL Server is used to return the month of the year i.e, from 1 to 12 for a date stated. Features : This function is used to find the month of the year for a date specified. This function comes under Date Functions. This function accepts only one parameter i.e, dat
2 min read
MAX() Function in SQL Server
MAX() : This function in SQL Server is used to find the value that is maximum in the group of values stated. Features : This function is used to find the maximum value.This function comes under Numeric Functions.This function accepts only one parameter namely expression. Syntax : MAX(expression) Par
2 min read
IIF() Function in SQL Server
IIF() function judges or evaluates the first parameter and returns the second parameter if the first parameter is true, otherwise, it returns the third parameter. IIF() function used in SQL Server to add if-else logic to queries.IIF is not supported in dedicated SQL pools in Azure Synapse Analytics.
2 min read
RANK() Function in SQL Server
The RANK() function is a powerful window function in SQL Server used to assign a rank to each row within a result set. It is particularly useful when we need to assign a rank to a group of rows based on some sorting criteria and want to differentiate between rows that have the same values. Unlike ot
5 min read
LTRIM() Function in SQL Server
The LTRIM() function in SQL Server removes all the space characters found on the left-hand side of the string. It removes the leading spaces from a string, SyntaxThe LTRIM function for SQL Server syntax is: LTRIM(string, [trim_string]) Parameter: string - The string from which the leading space char
2 min read
LOG() Function in SQL Server
The LOG() function returns the logarithm of a specified number or the logarithm of the number to the specified base. Syntax : LOG(number, base) Parameter : LOG() function accepts two-parameters as mentioned above and described below. number - This parameter hold a number which is greater than 0. bas
1 min read
ISDATE() Function in SQL Server
ISDATE() function : This function in SQL Server is used to check if the specified expression is a valid date or not. Features : This function is used to find if the stated date is valid or not. This function comes under Date Functions. This function accepts only one parameter i.e, an expression. Thi
2 min read
NULLIF() Function in SQL Server
NULLIF() function in SQL Server is used to check if the two specified expressions are equal or not. If two arguments passed to a function are equal, the NULLIF() function returns Null to us. NULLIF() function operates like a Like a CASE Statement. It will return the value of the first argument if th
3 min read
SQL Server LEN() Function
SQL SERVER LEN() function calculates the number of characters of an input string, excluding the trailing spaces. LEN() Function in SQL ServerThe LEN function in the SQL Server fetches the number of characters in a string. It counts the preceding spaces but not the trailing spaces. For eg, 'SQL SERVE
2 min read