0

I have a query on writing left exclusion joins when the data extensions has the composite primary key.

I have below two data extensions DE1

ContactID AccountID attribute
sksksksk 111111 six

DE 2

ContactID AccountID Cohort
sksksksk 111111 six

Now I want to write a SQL query to get all records from DE1 which are not in DE2. In my case in both the DEs, ContactID and AccountID are composite primary key.

I have done the left exclusion joins before only with one primarykeys.

Thanks

2
  • Can you please provide an example of the value of your composite PKs and what is the exact problem you faced when doing LEFT JOIN in your case?
    – Niko
    Aug 24, 2021 at 18:23
  • ContactID and the AccountID both are marked as primary key in the data extension.
    – Chandan
    Aug 24, 2021 at 23:50

1 Answer 1

1

You would do it similarly as you would have done it with just one Primary Key, just mentioning in the INNER JOIN 2 PKs and then also 2 PKs in the WHERE clause -

SELECT
a.ContactID,
a.AccountID,
a.attribute,
b.Cohort
FROM [Data_Extension_1] a
LEFT JOIN [Data_Extension_2] b ON a.ContactID = b.ContactID AND a.AccountID = b.AccountID
WHERE b.ContactID IS NULL AND b.AccountID IS NULL

Not the answer you're looking for? Browse other questions tagged .