Reputation: 31
I have a simple SQL query
SELECT NAME, FAMILY_NAME, AGE, SALARY, LOCATION
FROM TABLE
WHERE AGE > 34 and SALARY > 40000
and this works fine. But, I wish to exclude all the entry where NAME = 'ROBERTO' and FAMILY_NAME = 'D_SILVA'. How can I do this?
I am trying to impose not equal over NAME and FAMILY_NAME but that is excluding all the entries were Name = Roberto or FAMILY_NAME = 'D_SILVA'
Upvotes: 2
Views: 1170
Reputation: 808
By using parentheses, you can combine the filters. By nesting these filters (by adding parentheses) shown below and putting the "AND" keyword between the filters, you make sure both conditions have to be true.
SELECT [NAME], [FAMILY_NAME], [AGE], [SALARY], [LOCATION]
FROM [dbo].[TABLE]
WHERE [AGE] > 34
AND [SALARY] > 40000
AND NOT ([NAME] = 'ROBERTO' AND [FAMILY_NAME] = 'D_SILVA')
I recommend reading more about Logical Operator Precedence
Upvotes: 4