I have a table in MySQL with a number of normal fields and a number of “approval” fields that contain a 1 if the data in question is approved and a 0 otherwise. For example,
*==============================================================*
* id | fname | lname | fname_approved | lname_approved | ...*
*--------------------------------------------------------------*
* ... | ... | ... | 0 | 1 | ...*
In reality, there are many more columns, but it is just more of the same. What I would like to be able to do is select a single value, say all_approved that would be equal to 1 if all of the _approved fields contain 1 and would be equal to 0 if any of the fields contain a 0. Is there any easy way to do this in SQL, or do I need to handle it in my application logic?
You can use multiplication like
this way if any of the _approved is 0 then all_approved will be 0 otherwise 1