Mysql get column name when column value matches constraint?

There is no means in one query to dynamically scan through the table's schema and inspect its values. The best way to achieve what you want is the one you suggested: query for the row client-side and then cycle through the columns searching for the values you seek. The other alternative is to query for the table schema using the INFORMATION SCHEMA views client-side, build a SQL statement with a where clause that looks for a True value in all the boolean columns, execute that and inspect the results.

This is probably going to be rather ugly no matter how you cut it, but here's one option: select columns. Column_name from bool_table inner join information_schema. Columns on columns.

Table_schema = 'your_db' and columns. Table_name = 'bool_table' and ((columns. Column_name = 'bool_1' and bool_table.

Bool_1 = 1) or (columns. Column_name = 'bool_2' and bool_table. Bool_2 = 1)) where bool_table.

Id = 25 You could also potentially query information_schema. Columns to dynamically generate the list of column statements so that you could dynamically generate the query, and even execute it in a stored proc using dynamic sql in mysql.

I tried to get this working but wasn't quite successful... either way I think you're right when you say it's ugly so for readability alone I'm going to go with the don't do it answer as correct. I appreciate the work! – ace Apr 8 at 21:00.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions