• You might want to add a column to your queries, using ROW_NUMBER().

    Here's an example, but without some data more similar to the real data, it's hard to give a good option.

    WITH t1 AS(

    SELECT *,

    ROW_NUMBER() OVER( Order BY Id) AS rn

    FROM Table1

    ),

    t2 AS(

    SELECT *,

    ROW_NUMBER() OVER( Order BY Code) AS rn

    FROM Table2

    )

    SELECT *

    FROM t1

    JOIN t2 ON t1.rn = t2.rn

    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