views:

275

answers:

3

This is the sequel to this question.

I would like to combine three columns into one on a MySql select. The first two columns are boolean and the third is a string, which is sometimes null. This causes strange results:

Select *, (payment1_paid && ((payment2_paid || payment2_type ="none"))) as paid_in_full from payments

Note: payment1_paid is boolean, payment2_paid is boolean, payment2_type is varchar.

Note: Please ignore how ridiculous the structure of this table is. Behind every piece of bad code there is a long explanation :)

Edit: Null is not interesting to me for the varchar value. I only want to know if it's really "none."

Thanks in advance for your help!

+1  A: 

I guess you want NULL to be false? Try (payment_paid IS NULL || payment2_type = "none")

Greg
+1  A: 
Select *, 
      (payment1_paid && ((payment2_paid || coalesce(payment2_type,"null") ="none"))) 
         as paid_in_full 
from payments
TrickyNixon
+3  A: 

Hi, If null is not interesting then for you then:

Select *, 
      (payment1_paid && ((payment2_paid || (payment_type IS NOT NULL && payment_type="none"))) 
         as paid_in_full 
from payments

Good luck!

David Santamaria