Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the latest created table in MySQL?

Tags:

mysql

I have a MySQL database and every 6 months, a new table is created with the latest entries. What SQL command can get you the latest created table in a database?

Many thanks

like image 989
seedg Avatar asked Dec 05 '22 04:12

seedg


2 Answers

You can select the last create_time from information_schema.TABLES.

For example:

select table_name, create_time 
from information_schema.TABLES
where table_schema = 'andomar'
order by CREATE_TIME desc
limit 1
like image 126
Andomar Avatar answered Dec 07 '22 22:12

Andomar


You can display from a particular database

SELECT *
FROM information_schema.TABLES
WHERE table_schema = 'database_name'
ORDER BY `TABLES`.`CREATE_TIME` DESC
like image 37
Mahesh Malik Avatar answered Dec 07 '22 22:12

Mahesh Malik