0

When I write column!=something it also doesn't choose any null value and something. Why this happened? Can I prevent this just writing AND column is NULL?

1
  • Because null will allways be not fullfilling the condition if it is not beeing checked explicity. Commented Aug 8, 2016 at 6:12

3 Answers 3

2

You need to check for NULL too.

SELECT 
*
FROM your_table
WHERE column <> something
OR column IS NULL

Note: You cannot compare NULL with anything but NULL.

Let's look at the following code snippets:

SET @v := NULL;
SELECT @v = NULL;
Result: NULL; Because NULL can be only compared using IS NULL

SELECT @v IS NULL;
Result: 1 (i.e. TRUE)

The NULL value can be surprising until you get used to it. Conceptually, NULL means “a missing unknown value” and it is treated somewhat differently from other values.

To test for NULL, use the IS NULL and IS NOT NULL

WORKING WITH NULL VALUES IN MYSQL

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

1 Comment

Thank you for answering.First sentence was answer for me :)
1

Yes, you have check for NULL using the OR operator as 1000111 specified, not AND.

Also as you already know when using OR, if there are other AND operators in the WHERE clause then we need to enclose them with brackets ()

Regards

Comments

1

Need to check for NULL condition separately..

and column is NULL

2 Comments

Thanks for your answer I edit your answer a little bit
Okay..sure. Thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.