Home >Database >Mysql Tutorial >Maximum number of columns per group in MySQL
Let us understand how to find the maximum value of each set of columns in MySQL -
SELECT colName1, MAX(colName2) FROM tableName GROUP BY colName1 ORDER BY colName1;
We will now see an example. Suppose we have a table PRODUCT -
+---------+--------+ | Article | Price | +---------+--------+ | 1 | 255.50 | | 1 | 256.05 | | 2 | 90.50 | | 3 | 120.50 | | 3 | 123.10 | | 3 | 122.10 | +---------+--------+
The following is the query to get the maximum number of columns per group-
SELECT Article, MAX(Price) AS MaxPrice FROM Product GROUP BY Article ORDER BY Article;
+--------------+--------------+ | Article | MaxPrice | +--------------+--------------+ | 0001 | 256.05 | | 0002 | 90.50 | | 0003 | 123.10 | +--------------+--------------+
The above is the detailed content of Maximum number of columns per group in MySQL. For more information, please follow other related articles on the PHP Chinese website!