completed initial solution for selection queries