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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -