tree first sql