General Question

gsiener's avatar

How can I search for a specific column name in MySQL?

Asked by gsiener (454points) June 15th, 2007

E.g., I want to find any table that has the column called "Name"

Observing members: 0 Composing members: 0

4 Answers

andrew's avatar

SELECT table_name, column_name from information_schema.columns WHERE column_name LIKE 'Name';

gsiener's avatar

"Great answer!"

Falkon303's avatar

Thanx for the answer, you can also use -

SELECT column_name from information_schema.columns WHERE column_name LIKE ’%searchTerm%’ AND table_schema = ‘yourDB’

and to target a specific table -

SELECT column_name from information_schema.columns WHERE column_name LIKE ’%searchTerm%’ AND table_schema = ‘yourDB’ AND table_name = ‘yourDBTable’

<?
// PHP CODE //
mysql_connect(“dbHost”, “dbUserName”, “dbPassword”) or die(mysql_error());
mysql_select_db(“yourDB”) or die(mysql_error());

$cquery = mysql_query(“SELECT column_name from information_schema.columns WHERE column_name LIKE ’%searchTerm%’ AND table_schema = ‘yourDB’ AND table_name = ‘yourDBTable’”)or die(mysql_error());

while($cqueryres = mysql_fetch_assoc($cquery))
{
echo $cqueryres[‘column_name’];
}

?>

sss5's avatar

Hi,
I want to find any table that has the column called “Name” from database which i created in mysql

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther