AND, OR, NOT Operators

SQL FundamentalsDMLFree Lesson

Advertisement

AND, OR, NOT Operators

The AND, OR, and NOT operators combine or negate conditions in the WHERE clause.

💡 These logical operators let you build complex filters by combining multiple conditions.

AND Operator

Returns TRUE if all conditions are TRUE.

SELECT first_name, last_name, salary, department
FROM employees
WHERE department = 'Engineering' AND salary > 70000;

OR Operator

Returns TRUE if any condition is TRUE.

SELECT first_name, last_name, department
FROM employees
WHERE department = 'Engineering' OR department = 'Sales';

NOT Operator

Negates a condition.

SELECT first_name, last_name, department
FROM employees
WHERE NOT department = 'Engineering';

Operator Precedence

-- Order: NOT → AND → OR
-- Use parentheses for clarity:
SELECT * FROM employees
WHERE (department = 'Engineering' OR department = 'Sales')
  AND salary > 80000;

✅ Key Takeaways

  1. AND — all conditions must be TRUE
  2. OR — any condition must be TRUE
  3. NOT — negates a condition
  4. Precedence: NOT > AND > OR
  5. Use parentheses to make precedence clear

Advertisement

Need Expert SQL Help?

Get personalized SQL training or database consulting.

Advertisement