Page 1 of 1

getting a column name based on a value

Posted: Mon Sep 17, 2007 1:15 am
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

Re: getting a column name based on a value

Posted: Mon Sep 17, 2007 2:46 am
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?

Posted: Mon Sep 17, 2007 11:31 am
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

Posted: Mon Sep 17, 2007 12:00 pm
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

Posted: Mon Sep 17, 2007 1:11 pm
by nayeemmz
Yes that is exactly what I am looking for

Posted: Mon Sep 17, 2007 1:40 pm
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