How to find all the tables in MySQL with specific column names in them?
To get all tables with columns columnA
or ColumnB
in the database YourDatabase
:
SELECT DISTINCT TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME IN ('columnA','ColumnB')
AND TABLE_SCHEMA='YourDatabase';
SELECT TABLE_NAME, COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME LIKE '%wild%';
More simply done in one line of SQL:
SELECT * FROM information_schema.columns WHERE column_name = 'column_name';