Forum

Posted by Yuanyuan, March 2, 2022, 11:03 a.m.

#168 Why my code can not return 0

SELECT date, count(stream_id)num_streams
FROM dates D
left join video_stream VS
on D.date = VS.stream_dt
where date <= '2021-08-07' and date >= '2021-08-01'
and customer_country = 'US'
group by date

Answers

Hi Yuanyuan,
SQL engine executes queries in sequence, the WHERE clause will be executed after the JOIN condition is complete, and the WHERE condition will remove all NULLs.
Instead of adding the conditions in WHERE clause, you need to move it to the JOIN condition.
Hope it helps,
Leon
SQLPad user avatar

Leon (949)

March 4, 2022, 2:40 p.m.