I want to do a select in MySql that combines several columns... something like this pseudocode:
SELECT payment1_paid AND payment2_paid AS paid_in_full
FROM denormalized_payments
WHERE payment1_type = 'check';
Edit: payment1_paid and payment2_paid are booleans.
I can't use any other language for this particular problem than MySql.
Thanks for any help!
Edit: Sorry to everybody who gave me suggestions for summing and concatenating, but I've voted those early answers up because they're useful anyway. And thanks to everybody for your incredibly quick answers!
Just do
Select CONCAT(payment1_paid, payment2_paid) as paid_in_full
from denormalized_payments
where payment1_type = 'check';
You can concat any number of field you want.
If by combine you mean concatenate then this will work:
select concat(payment1_paid, payment2_paid) as paid_in_full
from denormalized_payments where payment1_type = 'check';
If by combine you mean add, then this should work:
select payment1_paid + payment2_paid as paid_in_full
from denormalized_payments where payment1_type = 'check';
[EDIT]
For boolean AND:
select payment1_paid && payment2_paid as paid_in_full
from denormalized_payments where payment1_type = 'check';
I am not sure but do you mean to concatenate?
SELECT CONCAT(ColumnA, ColumnB) AS ColumnZ
FROM Table
SELECT IF(payment1_paid = 1 AND payment2_paid = 1, 1, 0) AS paid_in_fill
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With