Param-Ganak
Param-Ganak

Reputation: 5875

How to get the list of table names from database in sorted order according to there creation date?

I am using MySQL Database. I have a database which contains tables. The number of tables are not constantin database. In my application there is a process which creats a new table into the database. I want to show these tablesnames in JComboBox.

I used following query to retrieve the table names.

show tables in dbinfo;

Now I want to retrieve the table names in sorted order. But the sorting should be done according to the creation date of the table.

is there any query which gives result as I required.

Thanks You!

Upvotes: 1

Views: 2536

Answers (4)

Naveen Kumar
Naveen Kumar

Reputation: 4601

Try this

SELECT table_name,Create_time FROM information_schema.tables
WHERE table_schema = 'yourDataBaseName' order by Create_time asc;

Upvotes: 1

Santosh
Santosh

Reputation: 17923

Every MySQL db has a INFORMATION_SCHEMA and it one of the tables (INFORMATION_SCHEMA.TABLES) has the data about tables. You can fire the query and get the table as per our needs. e.g.

SELECT table_name FROM INFORMATION_SCHEMA.TABLES
  where table_schema = 'empinfo' order by CREATE_TIME desc

Upvotes: 3

Harry Joy
Harry Joy

Reputation: 59670

You can use information_schema.TABLES to get table data by their creation date as:

SELECT table_name, create_time FROM information_schema.TABLES 
      where table_schema='myTableSchema' order by create_time;

Remove create_time column to only get table names. You can also change the ordering. Here myTableSchema is your database name, don't forget to use where condition otherwise it will get table names of all schema available on db server.

Upvotes: 2

chinna_82
chinna_82

Reputation: 6403

Select tables from (tablename) order by (date_field) desc.

Upvotes: -1

Related Questions