DataBolt

All Lessons

Introduction to SQL
SQL Lesson 1: Your Sample Database
SQL Lesson 2: SELECT — Reading data
SQL Lesson 3: WHERE — Filtering rows
SQL Lesson 4: AND, OR, NOT
SQL Lesson 5: BETWEEN, IN, LIKE
SQL Lesson 6: NULL — The Mystery Value
SQL Lesson 7: ORDER BY
SQL Lesson 8: LIMIT & OFFSET
SQL Lesson 9: Aggregate Functions
SQL Lesson 10: GROUP BY
SQL Lesson 11: HAVING
SQL Lesson 12: INNER JOINs
SQL Lesson 13: LEFT JOINs
SQL Lesson 14: RIGHT JOINs
SQL Lesson 15: SELF JOINs
SQL Lesson 16: UNION JOINs
SQL Lesson 17: Joining Multiple Tables
SQL Lesson 18: Subqueries
SQL Lesson 19: CTEs (WITH)
SQL Lesson 20: CASE Statements
SQL Lesson 21: Window Functions
SQL Lesson 22: String Functions
SQL Lesson 23: Date & Time Functions
SQL Lesson 24: INSERT, UPDATE, DELETE
SQL Lesson 25: CREATE TABLE & DDL
SQL Lesson 26: Indexes & Performance
SQL Lesson 27: Transactions & ACID
SQL Lesson 28: SQL Execution Order
SQL Lesson 29: 50 Practice Problems

CHAPTER 4

FILTERING - WHERE

WHERE filters which rows come back. Without it, you get every row.

IN THIS CHAPTER

  • Filtering rows with a single condition
  • All comparison operators: =, !=, >, <, >=, <=
  • Filtering numbers, text, and dates

🌟 Think of it this way: WHERE is the bouncer at the door. Only rows that satisfy the condition get through to your result. Everyone else it turned away.

4.1 - Basic Syntax

SQL

SELECT name, department, salary 
FROM employees
WHERE department = 'IT';

4.2 -All Comparison Operators

OPERATORMEANINGEXAMPLE
=Exact equaldepartment = 'IT'
!= or <>Not equalstatus != 'completed'
>Greater thansalary > 70000
<Less thansalary < 60000
>=Greater than or equalslalary >= 72000
<=Less than or equalsalary <= 62000

Find employees more than 70000

SELECT name, salary 
FROM employees
WHERE salary > 70000;

Exercise 👇

Exercise:

Tasks

1.👉Find all employees who work in the IT department
2.Find employees with salary greater than 60000.
3.Find employees who work in IT and earn more than 60000.
4.Find employees who are in HR or Marketing.
5.Find employees who do not have a manager.
Stuck? Read this task's