Chapter 2 · Lesson 1 of 3

WHERE Clause Basics

Filter rows with the SQL WHERE clause and comparison operators, then find every employee earning more than 80,000 in a sample table.

The WHERE clause filters rows based on a condition. Only rows that satisfy the condition are included in the result:

SELECT * FROM employees WHERE department = 'Engineering'

This returns only employees in the Engineering department.

Common comparison operators: = Equal to != Not equal to (also written <>) > Greater than < Less than >= Greater than or equal to <= Less than or equal to

For text values, remember to wrap them in single quotes: 'Engineering'.

Sample data

This lesson loads the employees table (8 rows) into DuckDB in your browser with one click, so you can run every example without uploading anything.

Setup SQL for employees
CREATE OR REPLACE TABLE employees (
    id INTEGER,
    name VARCHAR,
    department VARCHAR,
    salary DECIMAL(10,2),
    hire_date DATE
  );

INSERT INTO employees VALUES
    (1, 'Alice', 'Engineering', 95000, '2021-03-15'),
    (2, 'Bob', 'Marketing', 72000, '2020-07-01'),
    (3, 'Charlie', 'Engineering', 110000, '2019-01-10'),
    (4, 'Diana', 'Sales', 68000, '2022-11-20'),
    (5, 'Eve', 'Marketing', 78000, '2021-09-05'),
    (6, 'Frank', 'Engineering', 102000, '2020-02-28'),
    (7, 'Grace', 'Sales', 71000, '2023-04-12'),
    (8, 'Hank', 'Marketing', 65000, '2022-06-30');

Practice challenge

Find all employees with a salary greater than 80,000.

Hint: Use WHERE salary > 80000

Run your query in the editor and the lesson checks the result automatically.

Open this lesson in the SQL editor

Lessons in Filtering Data

Narrow results to the rows you need with WHERE, combine conditions with AND and OR, and match text patterns with LIKE.

  1. 01 · WHERE Clause Basics
  2. 02 · Combining Conditions
  3. 03 · Pattern Matching with LIKE

Related guides