- 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
How to get max(id) of row data in MySQL?
To get max(id), use MAX() method in MySQL. Following is the syntax −
select MAX(yourColumnName) AS anyAliasName from yourTableName;
Let us first create a table −
mysql> create table DemoTable710 (Id int); Query OK, 0 rows affected (0.53 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable710 values(1001); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable710 values(2001); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable710 values(1998); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable710 values(1789); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable710 values(1678); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable710 values(9087); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable710 values(1908); Query OK, 1 row affected (0.17 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable710;
This will produce the following output -
+------+ | Id | +------+ | 1001 | | 2001 | | 1998 | | 1789 | | 1678 | | 9087 | | 1908 | +------+ 7 rows in set (0.00 sec)
Following is the query to get max(id) of row data in MySQL −
mysql> select MAX(Id) AS Max_Id from DemoTable710;
This will produce the following output -
+--------+ | Max_Id | +--------+ | 9087 | +--------+ 1 row in set (0.00 sec)
- Related Articles
- Get MAX and MIN values along with their row id in MySQL?
- How to get element with max id in MongoDB?
- MySQL query to get max id from varchar type and the values in numeric?
- How to get the data associated with the maximum id in a MySQL table?
- How to get the max of two values MySQL?
- Only display row with highest ID in MySQL
- How to get the next auto-increment id in MySQL?
- How can I select the row with the highest ID in MySQL?
- How to get username using ID from another table in MySQL database?
- Sort data column to retrieve max textual value in MySQL
- How to determine the row that have min and max values in an R data frame column?
- Get MAX() on column in two MySQL tables?
- Get row data for the lowest and highest values in a MySQL column
- How to get device id in android?
- How to get the id after INSERT into MySQL database using Python?

Advertisements