0

Table Data:

enter image description here

I have this sql script:

SELECT
    ei.objid
FROM entityindividual ei 
INNER JOIN entity e 
    ON ei.objid = e.objid
LEFT JOIN entity_address ea 
    ON ei.objid = ea.parentid
WHERE ei.gender = 'M'
AND ISNULL(ea.barangay_name) LIKE '%'

If you run this script, 6 records will be displayed, but without using ISNULL(ea.barangay_name), only 1 record will be diplayed.

But consider this scenario:

SELECT
    ei.objid
FROM entityindividual ei 
INNER JOIN entity e 
    ON ei.objid = e.objid
LEFT JOIN entity_address ea 
    ON ei.objid = ea.parentid
WHERE ei.gender = 'M'
AND ISNULL(ea.barangay_name) LIKE '%BUENAVISTA%'

The PROBLEM is no records will display when you run the script above. WHY? How to fix this one?

2
  • what exactly are you doing here? AND ISNULL(ea.barangay_name) LIKE '%' Commented Aug 24, 2016 at 3:29
  • result of isnull(col) will be 1 or 0, what are you trying to get? Commented Aug 24, 2016 at 3:31

1 Answer 1

2

Try using coalesce instead of isnull.

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

SELECT
    ei.objid
FROM entityindividual ei 
INNER JOIN entity e 
    ON ei.objid = e.objid
LEFT JOIN entity_address ea 
    ON ei.objid = ea.parentid
WHERE ei.gender = 'M'
AND coalesce(ea.barangay_name,'') LIKE '%BUENAVISTA%'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.