Developer's Lab

By Diogo Pinto - DiØ

MySQL - Searching for Distinct Fields

When you haven’t idea where one or more columns name are available, you can search them on all table of the database, using the following clause:

1
2
3
4
SELECT DISTINCT TABLE_NAME
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE COLUMN_NAME IN ('COLUMN_NAME_DESIRED')
AND TABLE_SCHEMA='DATABASE_TARGET';

Where COLUMN_NAME_DESIRED is the name of the column to be searched and DATABASE_TARGET is the database where it must be searched.

Comments