I have a need to know which column names are used on more than one table of my database.
I've got this query as a start, which gives me a frequency table of column names across the database:
SELECT COLUMN_NAME, count(COLUMN_NAME) count
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA='dbName'
GROUP BY COLUMN_NAME
ORDER BY count DESC;
However, I'd like the query to also do the following:
Limit to only those records where
count>1
(I tried addingAND count>1
to theWHERE
clause, but I got the errorError Code: 1054. Unknown column 'count' in 'where clause'
)Show the names of all the tables on which each column appears (this could entail multiple rows per column name, one for each table name). If it's easier, I can leave off the
count
column, as long as condition 1 is met.
Note: This is similar to this question, but I don't want to search for a specific column; I want to find ALL column names that are repeated.