Ravindra BagaleCourses & study guides

10. MySQL Part 1: Install, Create, Insert and SELECT

10.7 LIKE, IN, BETWEEN and NULL

SELECT name FROM students WHERE name LIKE 'R%';          -- starts with R
SELECT name FROM students WHERE name LIKE '%Bagale';     -- ends with Bagale
SELECT name FROM students WHERE email LIKE '%a%@%';      -- 'a' before @
SELECT name FROM students WHERE name LIKE '_a%';         -- second letter a (_ = one char)
SELECT name, city FROM students WHERE city IN ('Pune', 'Nashik', 'Solapur');
SELECT name, city FROM students WHERE city NOT IN ('Pune');
SELECT name, age FROM students WHERE age BETWEEN 22 AND 25;          -- inclusive
SELECT name, joined_on FROM students WHERE joined_on BETWEEN '2026-03-01' AND '2026-03-31';
SELECT name FROM students WHERE email IS NULL;           -- not "= NULL"! → Raja
SELECT name FROM students WHERE age IS NOT NULL;
Wildcard Meaning Example
% Zero or more characters 'Pu%' → Pune
_ Exactly one character 'R_ja' → Raja

Ravindra Bagale's Tip

Writing WHERE email = NULL gives an empty result, and many students think there's no data. NULL means "unknown" – it can't be compared with =. Always use IS NULL / IS NOT NULL. This question comes up in interviews – remember it.

Practice task

Find students whose name contains "a" as the second letter, students aged 21–24, students from Nagpur or Kolhapur using IN, and students with no email.