My table is something like this:
Id | Name | ph_office | ph_home
1 | ab | 111 | NULL
2 | cd | NULL | 222
3 | ef | 333 | 444
4 | gh | NULL | NULL
and I want to append the name of that respective column to corresponding value. something like this:
Id | Name | phone
1 | ab | phone_office: 111
2 | cd | phone_home: 222
3 | ef | phone_office: 333, phone_home: 444
4 | gh | NULL
I tried using
select id, Name,
CONCAT('ph_office: ', COALESCE(ph_office,''),',','ph_home:',COALESCE(ph_home,'')) as phone
from contacts;
Id | Name | phone
1 | ab | ph_office: 111,ph_home:
2 | cd | ph_office:, ph_home: 222
3 | ef | ph_office: 333, ph_home: 444
4 | gh | ph_office:,ph_home
I want to ignore the column which has null. I am not much good at case
statements. How can it be done in mysql?
Thanks for your time