
- 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
Get all the tables from a MySQL database having a specific column, let’s say xyz?
Let’s say we have a database “web” and we need to get all the tables having a specific column ’StudentFirstName’.
For this, below is the query −
mysql> select myColumnName.table_name from information_schema.columns myColumnName where myColumnName.column_name = 'StudentFirstName' and table_schema='web';
This will produce the following output −
+---------------+ | TABLE_NAME | +---------------+ | demotable109 | | demotable297 | | demotable335 | | demotable395 | | demotable418 | | demotable425 | | demotable436 | +---------------+ 7 rows in set (0.14 sec)
Therefore, the above tables have one of the column names as “StudentFirstName”.
Let us check the description of any of the table to look for the column name ‘StudentFirstName’ −
mysql> desc demotable297;
This will produce the following output displaying one of the column names as “StudentFirstName” −
+------------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------------+--------------+------+-----+---------+-------+ | StudentId | int(11) | YES | | NULL | | | StudentFirstName | varchar(100) | YES | | NULL | | | StudentLastName | varchar(100) | YES | | NULL | | +------------------+--------------+------+-----+---------+-------+ 3 rows in set (0.01 sec)
- Related Articles
- Find a specific column in all the tables in a database?
- How do I select four random tables from a MySQL database having thousands of tables?
- Get record count for all tables in MySQL database?
- List down all the Tables in a MySQL Database
- Display all tables inside a MySQL database using Java?
- How to get the size of the tables of a MySQL database?
- How can I query for all the tables having a particular column name?
- How to find tables with a specific column name in MySQL?
- Copy from one column to another (different tables same database) in MySQL?
- Get a list of non-empty tables in a particular MySQL database?
- How can we get only the name having no other details about the tables in MySQL database?
- How to get a specific column record from SELECT query in MySQL?
- How can we get the list of tables in a particular database from MySQL Server command line?
- How can I check the character set of all the tables along with column names in a particular MySQL database?
- How to remove all instances of a specific character from a column in MySQL?

Advertisements