Update query logic.