- 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
MySql how to display the records with latest ID in a table?
Let us first create a table −
mysql> create table DemoTable676( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Number int ); Query OK, 0 rows affected (0.50 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable676(Number) values(1000); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable676(Number) values(1839); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable676(Number) values(29894); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable676(Number) values(1264); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable676(Number) values(190); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable676(Number) values(167); Query OK, 1 row affected (0.11 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable676;
This will produce the following output −
+----+--------+ | Id | Number | +----+--------+ | 1 | 1000 | | 2 | 1839 | | 3 | 29894 | | 4 | 1264 | | 5 | 190 | | 6 | 167 | +----+--------+ 6 rows in set (0.00 sec)
Following is the query to display the records with latest id number in a table −
mysql> select *from DemoTable676 order by Id DESC LIMIT 1;
This will produce the following output −
+----+--------+ | Id | Number | +----+--------+ | 6 | 167 | +----+--------+ 1 row in set (0.00 sec)
- Related Articles
- MySQL query to fetch the latest date from a table with date records
- How to select all the records except a row with certain id from a MySQL table?
- Display selected records from a MySQL table with IN() operator
- Exclude some ID records from a list and display rest in MySQL
- Display table records from a stored procedure in MySQL
- How to change the date in a table with date records with MySQL?
- MySQL query to display records from a table filtered using LIKE with multiple words?
- How to get the data associated with the maximum id in a MySQL table?
- How to implement Count (*) as variable from MySQL to display the number of records in a table?
- How can we display all the records from MySQL table with the help of PHP script?
- Display an error while inserting duplicate records in a MySQL table
- Only display row with highest ID in MySQL
- How to continuously publish the latest N records with sorting using MongoDB?
- How to order last 5 records by ID in MySQL
- How to display MySQL Table Name with columns?

Advertisements