Last updated

SQL AND, OR, NOT

Definition: AND, OR, and NOT combine or invert conditions inside a WHERE clause.

  • AND — every condition must be true
  • OR — at least one condition must be true
  • NOT — reverses a condition

Example 1 — AND

SELECT * FROM Customers
WHERE Country = 'Germany' AND Age > 35;

Example 2 — OR

SELECT * FROM Customers
WHERE Country = 'Germany' OR Country = 'Mexico';

Example 3 — NOT

SELECT * FROM Customers
WHERE NOT Country = 'Germany';

Example 4 — grouping with parentheses

SELECT * FROM Customers
WHERE (Country = 'Germany' OR Country = 'France') AND Age > 35;

💡 Tip: use parentheses to make the logic clear and to control which conditions are grouped together.

Try it Yourself
Output

          
Ad · responsive