Update select statement to use left join instead of IF and distinct row