I need to return only values from the Left column that do not exist in the Right column. Do not need the data matching with the right column.
I have two tables with the same metadata. Left table has 11137 records, Right table - 9725. (FYI, Left table has 8508 unique ID_pk; and Right table has - 7194 unique ID_pk.) I only need to return all the rows from the left table that not in the Right table.
I've tried various joints and CTE, but it returns 94857 for just join or 96463 for the left join.
(Select * From ##GlobalTempTable_PW_2
Select CTE.ID_pk, CTE.[Dweling_fk], CTE.FieldID, CTE.House
From CTE Join ##GlobalTempTable_LA_2 LA on CTE.ID_pk = LA.ID_fk
This task is usually accomplished using
Select * From ##GlobalTempTable_PW_2 PW WHERE NOT EXISTS (SELECT 1 FROM ##GlobalTempTable_LA_2 LA WHERE PW.ID_pk = LA.ID_fk)
This query returns all the records of table
##GlobalTempTable_PW_2 that don't have a matching record in table