LPS-51315 update sql to use left join
LPS-51315 add tests
LPS-51315 correct custom query
LPS-51315 SF