37

I'm trying to find if my database has a column named sort_method. I have had a look around the forums, but I don't seem to be able to find the right answer. My database has over 300 tables, so manually looking for it is not an option.

I'm using SQL queries from phpMyAdmin.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ledgemonkey
  • 7,223
  • 12
  • 36
  • 56
  • 6
    Dublicate of http://stackoverflow.com/questions/193780/how-to-find-all-the-tables-in-mysql-with-specific-column-names-in-them – kapandron Aug 17 '12 at 17:02

3 Answers3

77
SELECT table_name,table_schema
FROM INFORMATION_SCHEMA.COLUMNS
WHERE column_name='sort_method'
Andy
  • 1,618
  • 11
  • 13
8

You can query the INFORMATION_SCHEMA.COLUMNS system table:

SELECT COLUMN_NAME, TABLE_NAME
  FROM INFORMATION_SCHEMA.COLUMNS
  WHERE COLUMN_NAME = 'sort_method'

More information is in http://dev.mysql.com/doc/refman/5.0/en/columns-table.html.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mike Christensen
  • 88,082
  • 50
  • 208
  • 326
8

Try

SELECT DISTINCT TABLE_NAME 
     FROM INFORMATION_SCHEMA.COLUMNS
    WHERE COLUMN_NAME = 'columnName'
        AND TABLE_SCHEMA='YourDatabase';
John Woo
  • 258,903
  • 69
  • 498
  • 492