cancel
Showing results for 
Search instead for 
Did you mean: 

Only include emails once in query

lsauser
Participant
0 Kudos

Hi all,

Having a bit of a dead brain moment right now.

I have this query to give me BP Codes,Names, Contacts and Sales Person. I only want to include an existing email once in the query. If the same email exists for multiple BP's then only 1 BP should be included (lets say TOP 1).

SELECT DISTINCT 
OCRD.CardCode,
OCRD.CardName,
OCPR.Name,
OCPR.E_MailL,
OSLP.SlpName
FROM OCRD
INNER JOIN OCRG ON OCRG.GroupCode = OCRD.GroupCode
INNER JOIN OCPR ON OCPR.CardCode = OCRD.CardCode
INNER JOIN OOND ON OOND.IndCode = OCRD.IndustryC
INNER JOIN OSLP ON OCRD.SlpCode = OSLP.SlpCode
WHERE OCRG.GroupName <> 'Retail' AND
OOND.IndName = 'Aged Care' and
OCRD.frozenFor = 'N' AND
OCPR.E_MailL LIKE '%@%'
ORDER BY OCRD.CardCode ASC

For the life of me I cant figure it out right now. Any help will be appreciated.

Accepted Solutions (0)

Answers (0)