- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to find all tables that contains columnA and columnB in MySQL?
To find specific column names, use information_schema.columns Here, I am using Id in place of columnA and Name in place of columnB −
mysql> select table_name as TableNameFromWebDatabase -> from information_schema.columns -> where column_name IN ('Id', 'Name') -> group by table_name -> having count(*) = 3;
This will produce the following output. Following are the table with columns Id and Name −
+--------------------------+ | TableNameFromWebDatabase | +--------------------------+ | student | | distinctdemo | | secondtable | | groupconcatenatedemo | | indemo | | ifnulldemo | | demotable211 | | demotable212 | | demotable223 | | demotable233 | | demotable251 | | demotable255 | +--------------------------+ 12 rows in set (0.25 sec)
To prove, let us check the description of one of the tables. Following is the query −
mysql> desc demotable233;
This will produce the following output. Here, you can see we have the Int and Name columns −
+-------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+----------------+ | Id | int(11) | NO | PRI | NULL | auto_increment | | Name | varchar(20) | YES | | NULL | | +-------+-------------+------+-----+---------+----------------+ 2 rows in set (0.00 sec)
Advertisements