Back to course

Filtering Data with WHERE Clauses

Database Fundamentals: From Zero to Hero

Lesson 15: Filtering Data with WHERE Clauses

Retrieving an entire table is rarely useful. The WHERE clause allows you to filter the results based on specific conditions.

Basic Syntax with WHERE

sql SELECT [columns] FROM [table] WHERE [condition];

Comparison Operators

We use standard comparison operators within the WHERE clause:

OperatorMeaningExample
=EqualsWHERE Age = 30
>Greater thanWHERE Price > 50
<Less thanWHERE Quantity < 10
>=Greater than or equal toWHERE Sales >= 1000
!= or <>Not equal toWHERE Country <> 'USA'

Example 1: Filtering Numeric Data

Find all employees who earn more than 50,000.

sql SELECT Name, Salary FROM Employees WHERE Salary > 50000;

Example 2: Filtering Text Data

String values must be enclosed in single quotes (').

Find all products in the 'Electronics' category.

sql SELECT Name, Price FROM Products WHERE Category = 'Electronics';