Fix sql to we filter on the left join properly