Created query for pagination