I am having trouble with the following SQL statement. I have had this issue before but I can’t remember how I fixed the problem. I am guessing the issue with this is that MySQL sees 0 as null? Note I didn’t show the first part of the Select statement as it’s irrelevant. My SQL works. It’s showing rows with toffline that are = to 1 as well as 0…
FROM table1 AS tb1
LEFT JOIN table2 AS tb2 ON tb2.id = tb1.id2
LEFT JOIN table3 AS tb3 ON tb3.id = tb1.id3
AND tb1.toffline = 0
I have also tried AND NOT tb1.toffline = 1 also WHERE tb1.toffline = 0 all with the same result…
This is where indenting helps to see the issue. Your filtering is in the On clause not in a Where clause.
Thus, the system is going to filter Table3 before it evaluates the Left Join to Table1. If what you are attempting is to get all results where toffline is zero, then move that last filter to the Where clause:
EDIT Noticed that toffline is from Table1.