Correct SQL syntax for BETWEEN in ancestors query