I'm trying to add click on a certain alias to a data extension for segmentation purposes, but I find my query erroring with the 'Violation of PRIMARY KEY constraint. Cannot insert duplicate key.' error. Probably because the same subscriber can have multiple clicks.
How can I extend this query so it only returns the latest click by each subscriber
SELECT c.SubscriberKey,
m.EmailAddress,
m.Country,
m.Language,
m.Gender,
m.FirstName,
m.LastName,
m.Store,
m.StoreId,
c.LinkName
FROM _Click c
JOIN MasterSubscribers m on c.SubscriberKey = m.SubscriberKey
WHERE c.LinkName = 'WeLove_BornholmTable'
AND m.Consent_status = 'Confirmed'
AND c.EventDate > dateadd(hh,-24,getdate())
AND c.SubscriberKey NOT IN
(SELECT j.SubscriberKey FROM JourneyDE_WeLove_BornholmTable j)
I've tried using DISTINCT and tried adding GROUP BY, but have only caused syntax errors so far. Please guide me. Thank you :)