Table of Contents

    Using the MIN() Aggregate Function in SQL: A Comprehensive Guide

    Using the MIN() Aggregate Function in SQL: A Comprehensive Guide

    The MIN() function returns the smallest value of the selected column.

    The MAX() function returns the largest value of the selected column.

    Syntax:

    
    SELECT MIN(column_name)
    FROM table_name
    WHERE condition;
    

    We will apply MIN in this blow table:

    We will find the minimum Salary

    EmpId

    EmpName

    EmpAddress

    EmpSalary

    EmpDept

    1

    Rambo

    Kolkata

    30000

    ADMIN

    2

    Inza

    Bihar

    31000

    SALES

    3

    Samser

    Kolkata

    32000

    IT

    4

    Kamran

    Hydrabad

    33000

    ITIS

    5

    Azam

    Kolkata

    33000

    ITIS

    Example: MIN

    Code:

    
    SELECT MIN(EmpSalary) AS MinSalary FROM EmployeeDetails 
    

    Output:

    The above code will produce the following result-

    
    MinSalary 
    30000
    

    Code:

    USE SQLExamples
    DROP TABLE EmployeeDetails
    CREATE TABLE EmployeeDetails(
    EmpId int,
    EmpName VARCHAR(30),
    EmpAddress VARCHAR(50),
    EmpSalary VARCHAR(10),
    EmpDept VARCHAR(10)
    )
    
    INSERT INTO EmployeeDetails VALUES
    (1, 'Rambo', 'Kolkata', '30000', 'ADMIN'),
    (2, 'Inza', 'Bihar', '31000', 'SALES'),
    (3, 'Samser', 'Kolkata', '32000', 'IT'),
    (4, 'Kamran', 'Hydrabad', '33000', 'ITIS'),
    (5, 'Azam', 'Kolkata', '33000', 'ITIS')
    
    SELECT * FROM EmployeeDetails