Fix duplication issue in query