• This can be done with a recursive CTE. You can find many examples on the internet.

    It should be something like this:

    WITH RCTE AS(

    select T1.a1, T1.a2, T1.a3,

    T2.b1, T2.b2, T2.b3, T2.b4

    from T1

    JOIN T2 ON T1.a2=T2.a2

    WHERE T1.a1 IS NULL

    UNION ALL

    select T1.a1, T1.a2, T1.a3,

    T2.b1, T2.b2, T2.b3, T2.b4

    from T1

    JOIN T2 ON T1.a2=T2.a2

    JOIN RCTE ON T1.a1 = RCTE.a2

    )

    SELECT *

    FROM RCTE;

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2