Q:

How to do a left join on a run-time generated tables?

I have two tables in the database (myCustomTable1 and myCustomTable2) and from them I'm creating another two tables (Table1 and Table2) which are created during the run time. Now I need to take the rows which are inside of Table1, but are not in the Table2.
I found this question, which seems that contains the answer that I need, but I'm not able to implement this with my solution, because as said, tables which I need to "antijoin" are generated during run-time.
Both of my (run-time generated) tables have the format:
-----------------------
|  Column1 | Column2  |
-----------------------
|          |          |
-----------------------
|          |          |
-----------------------

Here is the code that I have.
SELECT Table1.* FROM (
    SELECT  myCustomTable1.Column1,
            myCustomTable1.Column2
    ) as Table1 
LEFT JOIN
(
    SELECT Table2.* FROM (
        SELECT  myCustomTable2.Column1,
                myCustomTable2.Column2
    ) as Table2 
)
ON  Table1.Column1 = Table2.Column1
AND Table1.Column2 = Table2.Column2

Now I'm aware that this solution is not working, because when trying to join, I'm trying to use Table2, which is not available in the global scope, but I can not find any appropriate solution.
Maybe using NOT EXISTS, LEFT OUTER JOIN or NOT IN is also an option, but in every try, I faced with the same issue where the scope of the defined tables is a problem.

A:

I find it a lot easier to separate your sets in CTEs:
;WITH Table1 AS
(
    SELECT  
        myCustomTable1.Column1,
        myCustomTable1.Column2
    FROM
        myCustomTable1
),
Table2 AS
(
    SELECT  
        myCustomTable2.Column1,
        myCustomTable2.Column2
    FROM
        myCustomTable2
)
SELECT *
FROM Table1 as t1
WHERE
NOT EXISTS (SELECT 1
            FROM Table2 as t2
            WHERE t1.Column1 = t2.Column1 
              AND t1.Column2 = t2.Column2);

