SQL Tutorial

SQL Introduction SQL Aggregate Functions SQL Aliases SQL And SQL Any All SQL Avg SQL Between SQL Case SQL Comments SQL Count SQL Delete SQL Distinct SQL Exists SQL Groupby SQL Having SQL In SQL Insert_into SQL Is Not Null SQL Join SQL Full Outer Join SQL Inner Join SQL Left Join SQL Right Join SQL Self Join SQL Like SQL Min Max SQL NOT Operator SQL Null SQL Operators SQL OR operator SQL OrderBy SQL Select SQL Select Into SQL Top Limit Fetch SQL Store Procedures SQL Sum SQL Union SQL Update SQL Where SQL Wildcards

SQL Database

SQL Alter Table SQL Auto increment SQL BackupDB SQL Check SQL Constrains SQL Create View SQL CreateDB SQL CreateTable SQL Data types SQL Dates SQL DefaultConstrain SQL DropDB SQL DropTable SQL Foreign Key SQL Hosting SQL Index SQL injections SQL Not NULL SQL PrimaryKey SQL Unique SQL Views

SQL MIN and MAX Tutorial

Example Table

We will use the following table named products for our examples:


    CREATE TABLE products (
        product_id INT PRIMARY KEY,
        product_name VARCHAR(50),
        price DECIMAL(10, 2)
    );

    INSERT INTO products (product_id, product_name, price) VALUES
    (1, 'Laptop', 999.99),
    (2, 'Smartphone', 499.99),
    (3, 'Tablet', 299.99),
    (4, 'Monitor', 199.99),
    (5, 'Keyboard', 49.99);
    

Products Table

product_id product_name price
1 Laptop 999.99
2 Smartphone 499.99
3 Tablet 299.99
4 Monitor 199.99
5 Keyboard 49.99

Using SQL MIN

SQL MIN is used to find the minimum value in a column.

Example: Find the Minimum Price

To find the minimum price of products, use the following query:


    SELECT MIN(price) AS min_price
    FROM products;
    

Result:

min_price 49.99

Using SQL MAX

SQL MAX is used to find the maximum value in a column.

Example: Find the Maximum Price

To find the maximum price of products, use the following query:


    SELECT MAX(price) AS max_price
    FROM products;
    

Result:

max_price 999.99