Hi anonymous user,
Please refer below several methods and check whether any of them is helpful to you.
You could also check the execution plan from your side and choose the fastest one.
SELECT *
FROM Records
WHERE Store = '1'
AND SaleNumber NOT IN
(SELECT DISTINCT SaleNumber FROM Records WHERE SalesPerson='Greg')
SELECT *
FROM Records P
WHERE P.Store = '1'
AND NOT EXISTS
(SELECT 1 FROM Records O WHERE SalesPerson='Greg' AND o.salenumber=p.salenumber)
SELECT P.*
FROM Records P
LEFT JOIN (SELECT O.Store,O.salenumber FROM Records O WHERE O.salesperson='Greg') A
ON P.salenumber=A.salenumber AND P.store=A.store
WHERE P.Store = '1' AND A.salenumber IS NULL
Best regards
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.