I have a table with parent/child relationship:
Table A
Column Id int
Column Parent_Id int
Column Description text
An example set of data would be:
999, NULL, 'Corp.'
998, 999, 'Div1',
997, 999, 'Div2',
510, 998, 'Child Div1A',
110, 997, 'Child Div2A',
120, 997, 'Child Div2B',
My query needs to return the lowest set of children, given a parent. So, for example, if given 999, I would return 510, 110, 120. But given 997, I would return only 110 and 120. If given 110, nothing would return. I can't figure out how to format my query quite correctly. I started by JOIN-ing the table on itself, but it seems like that would only get me 1 level down when I actually neeed to go N-levels down.