Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I search a MySQL database for a specific column name? [duplicate]

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.

like image 688
Ledgemonkey Avatar asked Aug 17 '12 16:08

Ledgemonkey


People also ask

How do I check if a column has duplicates in mysql?

Find duplicate values in one column First, use the GROUP BY clause to group all rows by the target column, which is the column that you want to check duplicate. Then, use the COUNT() function in the HAVING clause to check if any group have more than 1 element. These groups are duplicate.

How do I find a specific column in a mysql database?

You want to look for tables using the name of columns in them. SELECT DISTINCT TABLE_NAME FROM INFORMATION_SCHEMA. COLUMNS WHERE COLUMN_NAME IN('column1', 'column2') AND TABLE_SCHEMA = 'schema_name';


2 Answers

SELECT table_name,table_schema FROM INFORMATION_SCHEMA.COLUMNS WHERE column_name='sort_method' 
like image 70
Andy Avatar answered Sep 21 '22 01:09

Andy


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.

like image 30
Mike Christensen Avatar answered Sep 23 '22 01:09

Mike Christensen