But my first instinct would be to use hierarchical queries of some sort. Would they work?
I'd also look into some SQL reference books, like SQL for Smarties, or something.
Maybe modeling graphs in SQL?