Lesson Description
Keep only rows that match a condition.
Lesson 2 of 5
Progress: 0/4 exercises solved (0%)
Solve all exercises below to unlock the next lesson.
Lesson Description
Keep only rows that match a condition.
Easy Project
Mini project: Create a hiring shortlist query that filters by role, salary range, and hire date with deterministic ordering.
WHERE keeps only the rows that satisfy a condition. Without WHERE, every row in the table is returned.
SELECT columns
FROM table_name
WHERE condition;
| Operator | Meaning |
|---|---|
= | Equal |
!= or <> | Not equal |
<, > | Less / greater than |
<=, >= | Less / greater than or equal |
-- Employees earning above 10 000
SELECT first_name, last_name, salary
FROM employees
WHERE salary > 10000;
-- Only the IT department (id = 60)
SELECT first_name, last_name
FROM employees
WHERE department_id = 60;
-- A specific employee by name
SELECT *
FROM employees
WHERE last_name = 'King';
String comparisons are case-sensitive by default in PostgreSQL. Use ILIKE for case-insensitive matching (covered in the next course).
Dates can be compared directly using ISO format:
SELECT first_name, hire_date
FROM employees
WHERE hire_date > '2005-01-01';
WHERE is evaluated before SELECT, so you can filter on columns you are not selecting.WHERE clause per query; combine multiple conditions with AND / OR.This lesson is part of SQL Fundamentals. Focus on the core idea in WHERE: filtering rows, then validate with deliberate practice.
What to master
Common mistakes
High-level strategy
Task ladder
Transparent data checks
Retention loop
Logical reasoning for commands
WHERE
Why: Limits rows to only the business-relevant subset.
Memory cue: Filter early to reduce noise.
ORDER BY
Why: Makes output deterministic and reviewable.
Memory cue: No ORDER BY means no guaranteed row order.
AS alias
Why: Makes output columns readable for teams and reports.
Memory cue: If the name is clear, the query is easier to trust.
Concept check
3 quick questions. One at a time. Instant score at the end.
List the first_name, last_name, and salary of every employee with a salary above 10000.
Return the first_name and last_name of employees in department 60 (IT).
Return first_name, last_name, and hire_date for employees hired after 2005-01-01, ordered by hire_date ascending.
From the store sandbox, return name, price, and stock for products with price < 50 AND stock > 0, ordered by price ascending.
Lesson 2 of 5
0/4 solved (0%)
Finish this lesson to unlock next.