sql query adjusted to left join