- 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
Get the maximum value of a column with MySQL Aggregate function
To get the maximum value of a column, MySQL has a predefined aggregate function MAX(). Let us first create a table −
mysql> create table DemoTable ( Id int ); Query OK, 0 rows affected (0.96 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(100); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(988); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(1000); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(99); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(999); Query OK, 1 row affected (0.12 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+------+ | Id | +------+ | 100 | | 988 | | 1000 | | 99 | | 999 | +------+ 5 rows in set (0.00 sec)
Following is the query to get the maximum value of a column −
mysql> select max(Id) AS MaxId from DemoTable;
This will produce the following output −
+-------+ | MaxId | +-------+ | 1000 | +-------+ 1 row in set (0.03 sec)
- Related Articles
- Find the average of column values in MySQL using aggregate function
- How to get the maximum value from a column with alphanumeric strings beginning with specific characters in MYSQL?
- Get the maximum count of distinct values in a separate column with MySQL
- Fetch the maximum value from a MySQL column?
- Find the Maximum Value in a Column in MySQL
- How to get the count of a specific value in a column with MySQL?
- Which is the fastest way to get a column's maximum value in MySQL?
- How to select the maximum value of a column in MySQL?
- Call aggregate function in sort order with MySQL
- How to add column values in MySQL without using aggregate function?
- Two ways to fetch maximum value from a MySQL column with numbers
- Create an aggregate checksum of a column in MySQL
- Find maximum value from a VARCHAR column in MySQL
- How to get the maximum value from strings with integers in MySQL?
- How MySQL aggregate functions can be combined with MySQL IF() function?

Advertisements