improvement in Raw SQL join condition