Select data from show tables MySQL query
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
SHOW TABLES in MySQL lists all tables in the current database, but you cannot directly use it in a subquery or SELECT FROM. To filter, search, or programmatically work with table names, query the information_schema.TABLES system table instead. This gives you a standard SQL result set that supports WHERE, JOIN, LIKE, and any other clause — something SHOW TABLES does not allow.
Basic SHOW TABLES Usage
Why You Cannot SELECT FROM SHOW TABLES
Using information_schema Instead
The information_schema.TABLES view gives you the same data as SHOW TABLES but as a regular queryable table:
Practical Examples
Find Tables by Column Name
Find Large Tables
Count Rows Across All Tables
Note: TABLE_ROWS is an estimate for InnoDB tables. For exact counts, you need SELECT COUNT(*) FROM each_table.
Dynamic Query Generation
Generate SQL statements for all matching tables:
Using with Stored Procedures
SHOW TABLES Variants
Common Pitfalls
- Using SHOW TABLES in subqueries:
SHOWcommands are not SQL statements — they cannot be nested inSELECT,WHERE, orJOIN. Always useinformation_schemafor programmatic access. - TABLE_ROWS is approximate for InnoDB: The
TABLE_ROWScolumn ininformation_schema.TABLESis an estimate. For exact counts, runSELECT COUNT(*)on each table individually. - Forgetting the TABLE_SCHEMA filter: Without
WHERE TABLE_SCHEMA = 'mydb', queries againstinformation_schema.TABLESreturn tables from ALL databases on the server, which can be slow and confusing. - Case sensitivity with LIKE: On case-sensitive filesystems (Linux), table names in
LIKEpatterns are case-sensitive.LIKE 'User%'andLIKE 'user%'return different results. - Performance on large schemas: Querying
information_schemacan be slow on servers with thousands of tables. MySQL 8.0 caches this metadata, but older versions scan table files on disk.
Summary
SHOW TABLESlists tables but cannot be used in subqueries orSELECT FROM- Use
information_schema.TABLESfor full SQL access to table metadata - Filter by
TABLE_SCHEMA(database name) andTABLE_NAMEfor specific results information_schema.COLUMNSlets you find tables by column name- Use
SHOW FULL TABLESorTABLE_TYPEininformation_schemato distinguish base tables from views
Related reading
- SELECT FROM X WHERE id IN ... with Dapper ORM
- Select last N rows from MySQL
- Select last row in MySQL
- SELECT list is not in GROUP BY clause and contains nonaggregated column .... incompatible with sql_modeonly_full_group_by
- Select MongoDB documents where a field either does not exist, is null, or is false?
- Select multiple columns using Entity Framework
- Select Pandas rows based on list index
- Select records from NOW -1 Day

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.