by wefarrell · 6y ago · 0 comments
SELECT * FROM my_table WHERE my_column NOT IN (5, 6) SELECT * FROM my_table WHERE my_column != 5 OR my_column IS NULL;
This is because what you are selecting for is two conditions: when the value is != 5 and when the value is NULL so the result of != 5 is unknown.FWIW I agree with you that NULL's are counter-intuitive. While I am more or less aware of all the various ways to account for them, I still gravitate towards SQL schemas without NULL's since I prefer the intuitiveness of 2VL when writing or reading SQL.
COALESCE(my_column, -1)
might work for you in this case. See [1] for documentation on it in Postgres (it is in ANSI SQL though).[1]: https://www.postgresql.org/docs/current/functions-conditiona...
SELECT * FROM my_table WHERE my_column NOT IN (5, 6) AND my_column IS NOT NULL
happy now?
SELECT * FROM my_table WHERE my_column NOT IN (5, 6)
SELECT * FROM my_table WHERE my_column NOT IN (5, 6) AND my_column IS NOT NULL
Because "my_column NOT IN (5, 6)" will exclude NULL values.`select * from table where column not in (5,6)`
Can you name one that does?