Link to home
Start Free TrialLog in
Avatar of maunded
maunded

asked on

Find column name by value

Hi,
Im trying to find the name of a column using a value in that column.  I know it could be ambigious, but I'll have to deal with that.
What I have is a table like:
ID | Input1 | Input2 | Input3 | Input4
--------------------------------------------
1  | front   | back    | top      | side
2  | water | fire      | earth   | air
--------------------------------------------

I have the ID and one of the values in the table, but I need to be able to find the column that that value belongs to.
Is this possible?
Thanks
D.

Avatar of dqmq
dqmq
Flag of United States of America image

Sort of an inverse cross-tab :>).

Try:

Select 'Input1' from yourtable where Input1 = 'YourValue'
Union
Select 'Input2' from yourtable where Input2 = 'YourValue'
Union
Select 'Input3' from yourtable where Input3 = 'YourValue'
Union
Select 'Input4' from yourtable where Input4 = 'YourValue'
ASKER CERTIFIED SOLUTION
Avatar of dqmq
dqmq
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of maunded
maunded

ASKER

Both very nice, thank you.