
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Show Tables Sorted by Table Name
You can sort the table_name property from INFORMATION_SCHEMA.TABLES with ORDER BY clause. Sort in ascending order or descending order with the help of ASC or DESC respectively. The syntax is as follows −
SELECT table_name FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND table_schema='yourDatabaseName' ORDER BY table_name DESC;
Use the database with the name sample and have some tables. First, we will show all tables after that we will apply to sort on the table name. The query to display all tables is as follows −
mysql> show tables;
The following is the output −
+--------------------------+ | Tables_in_sample | +--------------------------+ | blobsizedemo | | insert_prevent | | insertrecord_selecttable | | insertrecordprevent | | mytable | | newlinedemo | | notequaloperator | | sumofeverydistinct | | yourtable | +--------------------------+ 9 rows in set (0.00 sec)
Here is the query to sort by table name. Now, let us display all tables in descending order with ORDER BY clause −
mysql> SELECT table_name -> FROM information_schema.tables -> WHERE table_type = 'BASE TABLE' AND table_schema='sample' -> ORDER BY table_name DESC;
The following is the output −
+--------------------------+ | TABLE_NAME | +--------------------------+ | yourtable | | sumofeverydistinct | | notequaloperator | | newlinedemo | | mytable | | insertrecordprevent | | insertrecord_selecttable | | insert_prevent | | blobsizedemo | +--------------------------+ 9 rows in set (0.00 sec)
Advertisements