Table of Contents

    Mastering the MAX() Aggregate Function in SQL: A Complete Guide

    Mastering the MAX() Aggregate Function in SQL: A Complete 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 MAX(column_name)
    FROM table_name
    WHERE condition;
    

    We will apply MAX function in this blow table:

    We will find the maximum 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: MAX

    Code:

    
    SELECT MAX(EmpSalary) AS MaxSalary FROM EmployeeDetails 
    

    Output:

    The above code will produce the following result-

    
    MaxSalary
    33000
    

    Code: Code For table creation and Data Insertion

    
    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