Is it possible to do a outer apply on two tables from different database engines to get unmatched records?

37 Views Asked by At

I am trying to find records that are in table C but not in table M in a column called records. I am doing an outer apply but the query does not finish executing. It does not give any errors. The two tables are in different database engines. I am confident that I am doing it correctly because I can do a left outer join - it is not giving me the results I want hence trying an outer apply. Below is my query.

SELECT M.records, C.records,
    CASE WHEN M.records = C.records
        THEN '1'
        ELSE '0'
    END
    AS RESULT
FROM [DB_1].[dbo].[Records_Overview] M
OUTER APPLY [DB_2].[dbo].[Records_Individual] C
WHERE M.record_Type = 'individual'

If anyone has another way of solving this please add. I am open to trying different methods. Just to reiterate, I am trying to find records that are in the column records of table M but not in the column records of table C.

Thanks in advance.

Edit: Below is my desired results.

M.records C.records result
123 123 1
122 NULL 0
321 321 1
NULL 332 0
768 567 0
454 454 1
790 NULL 0
NULL 209 0
0

There are 0 best solutions below