How can I search for a specific column name in MySQL?
Asked by
gsiener (
454)
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
SELECT table_name, column_name from information_schema.columns WHERE column_name LIKE 'Name';
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’];
}
?>
Hi,
I want to find any table that has the column called “Name” from database which i created in mysql
Answer this question
This question is in the General Section. Responses must be helpful and on-topic.