Fixed issue with generated SQL when more than one JOIN.