Express union which is dependent on other results
If I understood the question well, your task can be solved by using recursive queries. Oracle (see  and SQLServer (2005 and higher) both support it. Surely, different RDMS vendors use a slightly different syntax.