get query from the right place