I have realized that these two queries do not work if ‘fk_building’ is null. I don’t understand why, and cant seem to find a good explanation as it is kind of hard to google. Can someone explain why the hell !=3 doesnt return everything that is not 3??? including null rows? Why do I need to use <=> ?
update floor set fk_building = 3 where fk_building != 3 and floor_id = 1;
or
select * from floor where fk_building != 3
do not work where fk_building is null.
I would recommend looking at the “Common Mistakes” section on
NULLvalues on Wikipedia.From the entry:
As users have suggested, you can use a null safe operator if your RDBMS allows it, or check for
IS NULL.