mysql - How to handle null field value when using LIKE -


table data:

enter image description here

i have sql script:

select     ei.objid entityindividual ei  inner join entity e      on ei.objid = e.objid left join entity_address ea      on ei.objid = ea.parentid ei.gender = 'm' , isnull(ea.barangay_name) '%' 

if run script, 6 records displayed, without using isnull(ea.barangay_name), 1 record diplayed.

but consider scenario:

select     ei.objid entityindividual ei  inner join entity e      on ei.objid = e.objid left join entity_address ea      on ei.objid = ea.parentid ei.gender = 'm' , isnull(ea.barangay_name) '%buenavista%' 

the problem no records display when run script above. why? how fix one?

try using coalesce instead of isnull.

http://www.w3resource.com/mysql/comparision-functions-and-operators/coalesce-function.php

select     ei.objid entityindividual ei  inner join entity e      on ei.objid = e.objid left join entity_address ea      on ei.objid = ea.parentid ei.gender = 'm' , coalesce(ea.barangay_name,'') '%buenavista%' 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -