clean up join sql generation