How to SELECT with IF clause in mysql over query -
i want select columns id_thread
, no_tlp
, , nama
(contact name)
but not number save on tb_contact
(eg: sms addres sms-gateway, have auto name value)
so if nama = null set 'nama'='no_tlp'
select id_thread, no_tlp, if(tb_contact.`nama` = 'null' set nama = no_tlp) nama tb_sms left join tb_contact on tb_sms.`no_tlp` = tb_contact.`no_tlp` group id_thread asc
that's query didn't work,
somebody me please
try this;)
select id_thread, tb_contact.`no_tlp`, if(tb_contact.`nama` null, tb_contact.`no_tlp`, tb_contact.`nama`) nama tb_sms left join tb_contact on tb_sms.`no_tlp` = tb_contact.`no_tlp` group id_thread asc
or use coalesce
like:
select id_thread, tb_contact.`no_tlp`, coalesce(tb_contact.`nama`, tb_contact.`no_tlp`) nama tb_sms left join tb_contact on tb_sms.`no_tlp` = tb_contact.`no_tlp` group id_thread asc
Comments
Post a Comment