Beginner's problem with left join.
A beginner's problem. I have a screenshot, but I will try to retype. Using 3.35.5 through sqlite3.exe.
select var1,var2,var3,var4,var5,var6 from a left join b;
select var1,var2,var3,var4,var5,var6 from a left join b on ((a.var1=b.var4) and (a.var2=b.var5));
Now I want to select rows in the result by the value of b.var6. In particular, I want to include rows like the second of the three rows above.
select var1,var2,var3,var4,var5,var6 from a left join b on ((a.var1=b.var4) and (a.var2=b.var5)) where b.var6=NULL;
BUT NO ROWS ARE RETRIEVED. Same result with "where b.var6=''.
How can I do this?
Thanks for any ideas.
NULL values are not equal to anything, not even to other NULL values.
b.var6 IS NULL.
(There are also comparison operators
IS DISTINCT FROM and
IS NOT DISTINCT FROM that can tell the difference between null and non-null values. But that is getting too verbose, when you already know that you want to compare with NULL.)
You cannot use "=" when comparing with NULL's. Replace "=" with "is" and you will get the results you are hoping for. Nothing ever equals NULL (in the sense that "=" implies). You can use "is" for even regular comparisons where "=" will work (like comparing non-null numbers), so I have gotten into the habit of simply using "is" wherever I would think of using "=".