Skip to content

Searching through multiple tables for a specific column name in a MySQL database is a common task that can greatly improve your understanding of your database’s structure and relationships. By mastering a few simple SQL queries in the post below, you can significantly enhance your database management skills.

How to search for a specific column name in all tables in MySQL?

Query the INFORMATION_SCHEMA.COLUMNS table to find every table that includes a particular column name. This system table stores metadata about all the columns across all tables in your database. Execute the following SQL command:

SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME = 'your_column_name'
AND TABLE_SCHEMA = 'your_database_name';

Make sure to replace 'your_column_name' with the column you’re searching for and 'your_database_name' with the name of your database.

How to perform a case-insensitive search in MySQL?

Utilize the LOWER() function to perform a case-insensitive search if you’re uncertain about the column name’s exact case:

SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE LOWER(COLUMN_NAME) = LOWER('your_column_name')
AND TABLE_SCHEMA = 'your_database_name';

This approach ensures that the search ignores case differences by converting both the column names in the database and the input column name to lowercase before comparison.

Search within a specific database

Direct your search within a specific database by setting the correct database as your connection context or by explicitly specifying the TABLE_SCHEMA in your query:

SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME = 'your_column_name'
AND TABLE_SCHEMA = 'your_database_name';

This ensures the accuracy and relevance of your search results.

Extend results with column data type

Enhance your query to include the data type of each column by adding the DATA_TYPE field:

SELECT TABLE_NAME, DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME = 'your_column_name'
AND TABLE_SCHEMA = 'your_database_name';

This modification provides a more detailed view of the tables, including the types of the columns you find.

Use wildcards for flexible column name matching

Implement the LIKE operator with wildcards to find columns matching a pattern:

SELECT TABLE_NAME, COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME LIKE '%part_of_column_name%'
AND TABLE_SCHEMA = 'your_database_name';

Replace %part_of_column_name% with your desired pattern. The % wildcard represents any number of characters, offering flexible search capabilities.

By using these SQL queries effectively, you can streamline the exploration and management of your MySQL database, making it a more manageable and understandable entity.

Written by

Robert Cooper avatar

Robert Cooper

Senior Engineer at Basedash

Robert Cooper is a senior engineer at Basedash who builds full-stack product systems across SQL data infrastructure, APIs, and frontend architecture. His work focuses on application performance, developer velocity, and reliable self-hosted workflows that make data operations easier for teams at scale.

View full author profile →

Looking for an AI-native BI tool?

Basedash lets you build charts, dashboards, and reports in seconds using all your data.