I get different outputs for these queries. Did anyone face this?
-
1The `= null` comparison is invalid SQL. Use `is null`. – jarlh Aug 23 '18 at 07:49
4 Answers
The col= null
would not work because
NULL means I don't know. which is a placeholder to say there is the absence of a value.
=
evaluate for values, so that will not to work.
You need to use IS NULL
to get NULL
row value.

- 44,943
- 6
- 31
- 51
That's completely normal. "X = NULL" is NULL, which amounts to false ("NOT X = NULL" is also false; NULL is falser than false). For most SQL dialects.

- 2,240
- 20
- 18
=NULL IS is an expression of a value and IS NULL is the preferred method of evaluating the condition of a variable being NULL.
Here is the detail description Click here

- 689
- 3
- 8
-
1OP using Postgres, not MS SQL. There `IS NULL` is **only** valid method for checking, not preferred as you mentioned. – Evgeny Nozdrev Aug 23 '18 at 09:22
-
The first statement, SELECT * FROM bookings where code = null--
It Checks Directly if any row has the value null
The Second Statement, SELECT * FROM bookings where code IS null
It Checks all the rows its a null or not..

- 153
- 8