devxlogo

Selecting the Max, Min and Sum of Values from a Table in MySQL

Selecting the Max, Min and Sum of Values from a Table in MySQL

Considering the following table STOCKPRICE and its details.

CREATE TABLE 'STOCKPRICE' ('ID' INT(11) NOT NULL,'NAME' TEXT NOT NULL COLLATE 'utf8_bin','PRICE' INT(11) NOT NULL)COLLATE='utf8_bin'ENGINE=InnoDB;

Also, use the following to create sample data as below.

INSERT INTO 'STOCKPRICE' ('ID', 'NAME', 'PRICE') VALUES (1, 'ABC Ltd', 15);INSERT INTO 'STOCKPRICE' ('ID', 'NAME', 'PRICE') VALUES (2, 'XYZ Ltd', 19);INSERT INTO 'STOCKPRICE' ('ID', 'NAME', 'PRICE') VALUES (3, 'AAA Ltd', 16);

Now, you can find out the maximum, minimum values and sum of values in the PRICE column using the queries below:

For Max value -- SELECT MAX(PRICE) MAXPRICE FROM STOCKPRICEFor Min value -- SELECT MIN(PRICE) MINPRICE FROM STOCKPRICEFor SUM of all values -- SELECT SUM(PRICE) SUMPRICE FROM STOCKPRICE
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist