I was just wondering whether there is a simple statement to get all columns of a row that equals a defined value.
I have a table which represent the rights a user has.
e.g.
userid | right A | right B | right C | right D
----------------------------------------------
1 | 0 | 0 | 1 | 1
----------------------------------------------
2 | 1 | 0 | 1 | 1
----------------------------------------------
3 | 0 | 0 | 0 | 1
i need a query that returns me all colums of a user that has the value 1
for user 2 the result would look like
'right A', 'right C', 'right D'
at the moment i load the complete row and iterate over the result to get the column names but i would love to do this directly in my query.
According to MySQL a where clause in show columns etc. only tests the name, but not a value of a specific row.
A query to filter all values out of a result that are not 1 would also help, but i must work without knowing all the column names :-/
maybe a procedure is an option but thats just outsourceing the code from php to mysql :-/
Any ideas or complete impossible?
Thank in advance! :)