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 6

BETWEEN, IN, LIKE

Smarter filters for rnages, lists, and patterns.

IN THIS CHAPTER

  • BETWEEN for range filtering (inclusive)
  • IN to match against a list of values
  • NOT IN to exclude a list
  • LIKE with % and _ wildcards for pattern matching

6.1 - BETWEEN

Salary between 60000 and 75000

SELECT name, salary 
FROM employees
WHERE salary BETWEEN 60000 AND 75000;

🌟 Note: BETWEEN is inclusive on both ends. BETWEEN 60000 AND 75000 is exactly equivalent to salary >= 60000 AND salary <= 75000

6.2 - IN

Employes in IT or HR

SELECT name, department 
FROM employees
WHERE department IN ('IT', 'HR');

Pro Tip: IN is cleaner than chaining multiple OR conditions. WHERE dept IN ('IT','HR','Finance','Legal') vs four OR conditions — it's more readable and equally fast

6.3 - LIKE Pattern Matching

PatternMatchesExample matches
LIKE 'A%'Starts with AArjun, Ananya
LIKE '%a'Ends with aPriya, Sneha, Divya, Meera
LIKE '%i%'Contains i anywherePriya, Vikram, Divya, Kiran
LIKE '_i%'Second character is iVikram, Divya, Kiran
LIKE 'S___h'5 chars: S + 3 any hSneha

Names ending with 'a'

SELECT name 
FROM employees
WHERE name LIKE '%a';

Exercise 👇

Exercise:

Tasks

1.👉Find employees whose salary is between 60000 and 80000.
2.Find employees hired between 2021-01-01 and 2022-12-31.
3.Find employees who are in IT or HR using IN.
4.Find employees whose name starts with 'R'.
5.Find employees: who are in IT or Sales, and have salary between 60000 and 90000.
Stuck? Read this task's