Correct query logic