getting a column name based on a value

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
nayeemmz
Forum Commoner
Posts: 32
Joined: Fri Jun 29, 2007 7:19 pm

getting a column name based on a value

Post by nayeemmz »

Hi,

I am trying to obtain the column name of a data item in the database.

For example if I have a table A with a column reptiles. In this column reptiles I have an entry snake.

Now if I know about the value snake , how can I obtain its column name(which in the example is reptiles) using an sql statement.

I appreciate your help.

Thanks

-Nayeem
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Re: getting a column name based on a value

Post by volka »

nayeemmz wrote:For example if I have a table A with a column reptiles. In this column reptiles I have an entry snake.
Sounds weird.
What are the other columns of that table?
nayeemmz
Forum Commoner
Posts: 32
Joined: Fri Jun 29, 2007 7:19 pm

Post by nayeemmz »

Well all other columns are different.

For example I may have columnA columnB and so on
and I want to find the column name from a data item.


Thanks

-Nayeem
User avatar
ReverendDexter
Forum Contributor
Posts: 193
Joined: Tue May 29, 2007 1:26 pm
Location: Chico, CA

Post by ReverendDexter »

So what you're looking for would effectively be like the following? (though the following certainly doesn't work!)

Code: Select all

SELECT column_name
FROM table
WHERE data = "snake"
EDIT: reading is hard
nayeemmz
Forum Commoner
Posts: 32
Joined: Fri Jun 29, 2007 7:19 pm

Post by nayeemmz »

Yes that is exactly what I am looking for
nayeemmz
Forum Commoner
Posts: 32
Joined: Fri Jun 29, 2007 7:19 pm

Post by nayeemmz »

Thanks all for replying. I found an alternative solution to my problem and I wouldn't need to query the database like this any longer.

Thanks again.

-Nayeem
Post Reply