MIN Function

SQLite MIN function is used to fetch the minimum value of an expression.

Syntax:

SELECT MIN(aggregate_expression)  

FROM tables  

[WHERE conditions]; 

    Syntax when you use Min function with GROUP BY clause:

    SELECT expression1, expression2, ... expression_n  
    
    MIN(aggregate_expression)  
    
    FROM tables  
    
    [WHERE conditions]  
    
    GROUP BY expression1, expression2, ... expression_n; 

      Example1:

      We have a table named “STUDENT”, having the following data:

      Sqlite Min function 1

      Retrieve the lowest fees of the student from the “STUDENT” table:

      SELECT MIN(FEES) AS "Lowest Fees"  
      
      FROM STUDENT;

      Output:

      Sqlite Min function 2

      Example2:

      Using GROUP BY clause with MIN function:

      Retrieve NAME and MIN FEES from the table “STUDENT” and ORDER BY the data by NAME:

      SELECT NAME, MIN(FEES) AS "Lowest Fees"  
      
      FROM STUDENT  
      
      WHERE ID <= 5  
      
      GROUP BY NAME;   

        Output:

        Sqlite Min function 3

        Comments

        Leave a Reply

        Your email address will not be published. Required fields are marked *