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?
Asked
Active
Viewed 104 times
3 Answers
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

1000111
- 13,169
- 2
- 28
- 37
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

Community
- 1
- 1

Amitav Mohanty
- 11
- 4