Fix bug where select builds duplicate rows