1

I would appreciate a little help.

How do I write EXCEPT clause in Salesforce SQL?

I would like to have query which excludes rows based on a few conditions from the same database.

Like this:

SELECT Email_address
FROM Database_1
EXCEPT
SELECT Email_address
FROM Database_1
WHERE Brand_country = 'xyz' AND Address_country = 'abc'

Is there another keyword?

Or maybe is there a better/easier way to do this?

Thanks in advance!

Amberjack
  • 45
  • 5
  • If `EXCEPT` isn't available you can do `NOT EXISTS` (simple), or `GROUP BY` (a little harder.) – jarlh Nov 26 '20 at 13:04
  • NOT EXISTS is not simple for me. I am still figuring it out... but GROUP BY solution was just posted below. And it works like a charm. Thank you anyway. – Amberjack Nov 26 '20 at 13:30

1 Answers1

0

You can use aggregation:

SELECT Email_address
FROM Database_1
GROUP BY Email_address
HAVING SUM(CASE WHEN Brand_country = 'xyz' AND Address_country = 'abc' THEN 1 ELSE 0 END) = 0;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786