SQL AND / OR / NOT

Use AND, OR, and NOT to build complex filters in your WHERE clause.

๐Ÿ”น How They Work

  • AND โ€” all conditions must be true
  • OR โ€” at least one condition is true
  • NOT โ€” reverses the condition (negation)

๐Ÿ”น Examples

-- Both conditions must be true
SELECT * FROM employees 
WHERE department = 'IT' AND salary > 60000;

-- Either condition can be true
SELECT * FROM employees 
WHERE department = 'HR' OR salary > 70000;

-- Negate a condition
SELECT * FROM employees 
WHERE NOT department = 'Sales';

-- Combine all
SELECT * FROM employees 
WHERE (department = 'IT' OR department = 'HR') AND salary > 50000;

๐Ÿง  Quick Recap

OperatorMeaningExample
ANDBoth conditions trueWHERE dept = 'IT' AND salary > 60000
OREither condition trueWHERE dept = 'HR' OR salary > 70000
NOTNegates conditionWHERE NOT dept = 'Sales'

โœ… Use these to filter data precisely and flexibly!