1
col1 col2
null null
aaaa null
bbbb null

col1=col2 - no rows returned

not (col1=col2) - following returned

aaaa null
bbbb null 

Not (null) = null? so how is this being interpreted?

3
  • I think , Answer for this question is in: stackoverflow.com/a/1843460/4211782 Commented Nov 3, 2014 at 20:30
  • Here is a good tutorial about null values: at guru99.com/null.html Commented Nov 3, 2014 at 20:31
  • I just ran your second query in SQL fiddle, and it returns no rows: sqlfiddle.com/#!6/d41d8/22672. My best guess is that null is not null but 'null' -- the string, that is. Commented Nov 3, 2014 at 20:35

2 Answers 2

1

Comparing with null results in unknown which is false.

Use the is operator

where col1 = col2
or (col1 is null and col2 is null)

I added the () only for readabiliy. and has stronger operator precendence than or.

Sign up to request clarification or add additional context in comments.

2 Comments

no, null = null is null. null = a is also null. both are false then. I know the is operator, curious why null = null not returned.
Because NULL is not a known value. So if you have two unknowns you can't know if they are equal or not therefore they can't be equal.
0

Please use isnull(col1,0)=isnull(col2,0) because can't compare null with logical operations.

see below link: SQL is null and = null

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.