Perhaps these two queries may be different. I mean, the first query did not include all the rows from my left table, so I put the conditions in the join part.
Request 1
SELECT COUNT(*) as opens, hours.hour as point
FROM hours
LEFT OUTER JOIN tracking ON hours.hour = HOUR(FROM_UNIXTIME(tracking.open_date))
WHERE tracking.campaign_id = 83
AND tracking.open_date < 1299538799
AND tracking.open_date > 1299452401
GROUP BY hours.hour
Request 2
SELECT COUNT(*) as opens, hours.hour as point
FROM hours
LEFT JOIN tracking ON hours.hour = HOUR(FROM_UNIXTIME(tracking.open_date))
AND tracking.campaign_id = 83
AND tracking.open_date < 1299538799
AND tracking.open_date > 1299452401
GROUP BY hours.hour
The difference is that the first query gives me 18 lines, where there are no lines between points from 17 to 22. But when I run the second request, it shows 24 lines completely, but for lines between 17 and 22 it has a value of 1 ! I expected it to be 0 or NULL? If it is really 1, if it did not appear in the first request?
How did this happen?
source
share