1

This question already has an answer here:

I'm trying to query for records that do not contain LTD or LLP in the name and are also not assigned to a certain record type. I have tried just about every variation with parenthesis and AND/OR conditions but jo joy. Can anyone help? Fields removed for simplicity.

SELECT Full_Name__c, Account.Name FROM CONTACT 

WHERE 

NOT(account.name LIKE '%LTD%' OR account.name LIKE '%LLP%') 

AND

(RecordType.Name != 'Broker' OR account.RecordType.Name != 'Broker')

ORDER BY account.name

Note that the below query does work:

SELECT Full_Name__c, Account.Name FROM CONTACT 

WHERE 

NOT(account.name LIKE '%LTD%' OR account.name LIKE '%LLP%') 

ORDER BY account.name

marked as duplicate by Phil Hawthorn, Reshma, Vijay Ganji, Pranay Jaiswal, glls Aug 3 at 23:44

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

This is a bit of a guess but I think this is what you'd want. This would exclude the record if any of the listed conditions are true. I have changed your like query because I find it easier to read this way, but I believe yours should work too.

SELECT Full_Name__c, Account.Name
FROM Contact
WHERE (NOT Account.Name LIKE '%LTD%')
AND (NOT Account.Name LIKE '%LLP%') 
AND RecordType.Name != 'Broker'
AND Account.RecordType.Name != 'Broker'
ORDER BY Account.Name

Not the answer you're looking for? Browse other questions tagged or ask your own question.