function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sudiptaa GhoshSudiptaa Ghosh 

MINUS operator in SOQL

Can somebody pls tell how to do MINUS  in SOQL queries: 

Like in SQL:

SELECT supplier_id, supplier_name FROM suppliers WHERE supplier_id > 2000 MINUS SELECT company_id, company_name FROM companies WHERE company_id > 1000 ORDER BY 2;

Khan AnasKhan Anas (Salesforce Developers) 
Hi Sudiptaa,

Greetings to you!

You can use NOT IN keyword in SOQL. 
NOT IN: If the value does not equal any of the specified values in a WHERE clause.
 
SELECT Id FROM Account WHERE Id NOT IN (SELECT AccountId FROM Opportunity WHERE IsClosed = false)
 
List<Account> listOfAccounts = [SELECT Id, Name FROM Account WHERE Id NOT IN (SELECT AccountId FROM Contact)];

Please refer to the below link which might help you further.

https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_comparisonoperators.htm

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas