SQL - Example of MIN() and MAX() functions usage

By xngo on March 12, 2019

  • MIN() returns the minimum value of the column.
  • MAX() returns the maximum value of the column.
-- Create test data.
DROP TABLE IF EXISTS price;
CREATE TABLE price(DATE INT, OPEN DECIMAL, low DECIMAL, high DECIMAL);
INSERT INTO price(DATE, OPEN, low, high) 
    VALUES
        (20190112, 2.88, 2.17, 3.23),
        (20190117, 3.28, 2.99, 3.73),
        (20190123, 1.66, 0.87, 2.13);
SELECT * FROM price;
 
-- Select min() and max()
SELECT MIN(low), MAX(high) FROM price;

Output

date        open        low         high      
----------  ----------  ----------  ----------
20190112    2.88        2.17        3.23      
20190117    3.28        2.99        3.73      
20190123    1.66        0.87        2.13      
 
 
MIN(low)    MAX(high) 
----------  ----------
0.87        3.73   

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.