LIKE, IN, BETWEEN and IS NULL
Pattern matching and range filtering — essential for working with real-world messy data.
Find all employees whose name starts with "A".
SELECT * FROM employees
WHERE name LIKE 'A%';% matches any sequence of characters. _ matches exactly one character. So LIKE "_a%" means: any single character, then "a", then anything.
Find employees whose email contains "gmail".
SELECT * FROM employees
WHERE email LIKE '%gmail%';Placing % on both sides searches anywhere in the string. LIKE is not case-sensitive in MySQL by default but is in PostgreSQL.
Select employees from Sales, HR, or Finance departments.
SELECT * FROM employees
WHERE department IN ('Sales', 'HR', 'Finance');IN is cleaner than writing multiple OR conditions. NOT IN excludes those values. Be careful: NOT IN returns no rows if any value in the list is NULL.
Find employees with salary between 30000 and 60000.
SELECT * FROM employees
WHERE salary BETWEEN 30000 AND 60000;BETWEEN is inclusive — it includes both boundary values. Equivalent to: WHERE salary >= 30000 AND salary <= 60000.
Find all employees who have no manager assigned (manager_id is NULL).
SELECT * FROM employees
WHERE manager_id IS NULL;Never use = NULL. NULL means unknown, so NULL = NULL is not true — it is also NULL. Always use IS NULL or IS NOT NULL.
Find employees hired between Jan 2023 and Dec 2023.
SELECT * FROM employees
WHERE hire_date BETWEEN '2023-01-01' AND '2023-12-31';BETWEEN works on dates too. Always use ISO format (YYYY-MM-DD) for dates in SQL to avoid regional format confusion.
EVIKA ACADEMY · SQL FOR DATA ANALYTICS
Want to master SQL with live practice?
Join our SQL for Data Analytics course — live classes in Noida and online across India.
Book Free Demo Class →