- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Maximum of Column per Group in MySQL
Let us understand how to find the maximum of a column per group in MySQL −
SELECT colName1, MAX(colName2) FROM tableName GROUP BY colName1 ORDER BY colName1;
We will now see a live example. Let’s say we have a table PRODUCT −
<PRODUCT>
+---------+--------+ | Article | Price | +---------+--------+ | 1 | 255.50 | | 1 | 256.05 | | 2 | 90.50 | | 3 | 120.50 | | 3 | 123.10 | | 3 | 122.10 | +---------+--------+
Following is the query to get the maximum of column per group −
Query
SELECT Article, MAX(Price) AS MaxPrice FROM Product GROUP BY Article ORDER BY Article;
Output
+--------------+--------------+ | Article | MaxPrice | +--------------+--------------+ | 0001 | 256.05 | | 0002 | 90.50 | | 0003 | 123.10 | +--------------+--------------+
- Related Articles
- The Rows Holding the Group-wise Maximum of a Certain Column in MySQL
- MySQL query to display record with maximum count values in a group with other column values?
- GROUP BY a column in another MySQL table
- Group MySQL rows in an array by column value?
- What is the maximum length of MySQL VARCHAR column?
- MySQL query to group by column and display the sum of similar values in another column
- Find the Maximum Value in a Column in MySQL
- How to select the maximum value of a column in MySQL?
- The Row Holding the Maximum of a Certain Column in MySQL
- Find maximum value from a VARCHAR column in MySQL
- GROUP BY and display only non-empty column values in MySQL
- Fetch the maximum value from a MySQL column?
- Get the maximum value of a column with MySQL Aggregate function
- Get the maximum count of distinct values in a separate column with MySQL
- MySQL group by for separate id without using GROUP BY to remove duplicate column row?

Advertisements