logo

MySQL - How to list all tables that contain a specific column name?

Posted on
Authors

Problem

You want to look for tables using the name of columns in them.

Solution

SELECT DISTINCT
  table_name
FROM
  information_schema.columns
WHERE
  table_schema = 'schema_name'
  AND column_name IN('column_name_01', 'column_name_02')
SELECT DISTINCT
  table_name
FROM
  information_schema.columns
WHERE
  table_schema = 'schema_name'
  AND column_name IN('column_name_01', 'column_name_02')

Or a more simple way:

SELECT
  *
FROM
  information_schema.columns
WHERE
  column_name = 'column_name';
SELECT
  *
FROM
  information_schema.columns
WHERE
  column_name = 'column_name';