I have the query below, TBL1 X is my source table and TBL2 Y is my target table. I want to get only the data from TBL1 X that any of the fields indicated below don't match their corresponding fields in TBL2 Y. I am not a 100% sure that the code is correct. Can someone help please
SELECT
Col1,
Col2,
PRESC_ID,
PRSC_NPI_N,
FROM TBL1 X
JOIN
(
SELECT
CLAIM_ID,
ColA,
ColB,
ColC,
ColD
FROM TBL2 Y
)
ON X.PHARM_ID = Y.CLAIM_ID
---- If this condition X.PHARM_ID= Y.CLAIM_ID and any of the ones below is satisfied, I want the record to be return.
WHERE X.PHARM_ID= Y.CLAIM_ID
OR X.Col1 <> Y.ColA
OR X.Col2 <> Y.ColB
OR X.PRESC_ID <> Y.ColC
OR X.PRSC_NPI_N <> Y.ColD;