fix query that will return duplicate entries