CHAPTER 6
Smarter filters for rnages, lists, and patterns.
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
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
| Pattern | Matches | Example matches |
|---|---|---|
| LIKE 'A%' | Starts with A | Arjun, Ananya |
| LIKE '%a' | Ends with a | Priya, Sneha, Divya, Meera |
| LIKE '%i%' | Contains i anywhere | Priya, Vikram, Divya, Kiran |
| LIKE '_i%' | Second character is i | Vikram, Divya, Kiran |
| LIKE 'S___h' | 5 chars: S + 3 any h | Sneha |
Names ending with 'a'
SELECT name FROM employees WHERE name LIKE '%a';