
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
MySQL show tables sort 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)
- Related Articles
- Only show tables with certain patterns in MySQL “show tables”?
- What is the default sort order in MySQL tables?
- Sort a MySQL table column value by part of its value?
- What is the alias to Show Tables in MySQL Result?
- How can I change the default sort order of MySQL tables?
- Write a MySQL query equivalent to “SHOW TABLES” in sorted order?
- Show constraints on table command in MySQL?
- How ANALYZE TABLE statement helps in maintaining the MySQL tables?
- List MySQL tables and sizes ordered by size?
- MySQL stored procedure to execute SHOW CREATE TABLE?
- Sort by character length in MySQL
- How to find tables with a specific column name in MySQL?
- How to write PHP script by using ORDER BY clause inside it to sort the data of MySQL table?
- How to sort by value with MySQL ORDER BY?
- SHOW TABLE statement with multiple LIKE values in MySQL?

Advertisements