4

I expect the following code to show me all the records in the table where the exchange column is null but the result set show 0 rows. Any idea why?

SELECT * FROM pubco WHERE exchange IS NULL;
3
  • 1
    Either the table is empty or the there isn't any null value in the exchange column Commented Jan 11, 2013 at 14:15
  • 1
    there's no row with exchange NULL ! (maybe a DEFAULT value in the exchange column ?) Commented Jan 11, 2013 at 14:15
  • 2
    Perhaps what you think is NULL is actually the empty string ''. Commented Jan 11, 2013 at 14:16

4 Answers 4

6

maybe you have interpreted '' as NULL which is not the same, but try this

SELECT * 
FROM pubco 
WHERE exchange IS NULL OR
      exchange = ''

but if still not getting the value, maybe it has spaces on it, so you should TRIM it,

SELECT * 
FROM pubco 
WHERE exchange IS NULL OR
      TRIM(exchange) = ''
Sign up to request clarification or add additional context in comments.

1 Comment

you have nailed it. The problem was my interpretation of NULL vs. '' thanks for your help. Will accept answer when I can.
0

One important remark: NULL and '' (i.e. empty string) are not the same thing, most probably your column contains empty strings, so you need to put another condition:

SELECT * FROM pubco WHERE (exchange IS NULL OR exchange = '');

Comments

0

Are you sure they are null?

Maybe they have a string value "NULL" that is not the same, what does it returns if you do:

SELECT * FROM pubco WHERE exchange == "NULL";

Comments

0

Rather than using the this query

SELECT * 
FROM pubco 
WHERE exchange IS NULL OR
      exchange = ''

Try this

SELECT * FROM pubco 
WHERE isnull(exchange,'')='';

It will improve your performance.

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.