Filtering Data in SQL: Using WHERE, AND, OR, and NOT

Filtering Data with WHERE The WHERE clause filters rows that meet specific conditions. Example: SELECT * FROM users WHERE Age > 25; Combining Filters with AND, OR, and NOT AND: Filters rows that meet all conditions. SELECT * FROM users WHERE Age > 25 AND City = 'New York'; OR: Filters rows that meet at least one condition. SELECT * FROM users WHERE Age > 25 OR City = 'New York'; NOT: Excludes rows that meet the condition. SELECT * FROM users WHERE NOT Age

Apr 16, 2025 - 20:34
 0
Filtering Data in SQL: Using WHERE, AND, OR, and NOT

Filtering Data with WHERE

The WHERE clause filters rows that meet specific conditions.

Example:

SELECT * FROM users WHERE Age > 25;

Combining Filters with AND, OR, and NOT

  • AND: Filters rows that meet all conditions.
SELECT * FROM users WHERE Age > 25 AND City = 'New York';
  • OR: Filters rows that meet at least one condition.
SELECT * FROM users WHERE Age > 25 OR City = 'New York';
  • NOT: Excludes rows that meet the condition.
SELECT * FROM users WHERE NOT Age < 25;

Challenge: Write Complex Filters

Retrieve all orders placed in 2023 by users from New York or San Francisco.