
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
How to find all tables that contains two specific columns in MySQL?
To find two 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 tables 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)
- Related Questions & Answers
- How to find all tables that contains columnA and columnB in MySQL?
- Find MongoDB documents that contains specific field?
- Find documents that contains specific field in MongoDB?
- Rename all tables and columns to lower case in MySQL?
- How to find missing value between two MySQL Tables?
- How to find tables with a specific column name in MySQL?
- How to move data between two tables with columns in different MySQL databases?
- MySQL - Select all records if it contains specific number?
- Select all records if it contains specific number in MySQL?
- Find a specific column in all the tables in a database?
- Find document with array that contains a specific value in MongoDB
- How do I find an element that contains specific text in Selenium Webdriver?
- MySQL join two tables?
- How do I find an element that contains specific text in Selenium WebDriver (Python)?
- How to find out all elements that matches a specific condition in JavaScript?
Advertisements