Sometimes you do not know the exact value you are looking for. Maybe you remember
a student's name starts with "Am" but you are not sure of the rest. That is where
LIKE and wildcards come to the rescue.
The Percent Wildcard (%)
The % symbol matches any sequence of characters (including zero characters):
-- Names that start with 'A'
SELECT * FROM students WHERE name LIKE 'A%';
-- Names that end with 'a'
SELECT * FROM students WHERE name LIKE '%a';
-- Names that contain 'in' anywhere
SELECT * FROM students WHERE name LIKE '%in%';
The % wildcard is the one you will use the most. It is incredibly flexible.
The Underscore Wildcard (_)
While % matches anything, _ matches exactly one character:
-- Names that are exactly 5 letters long and start with 'J'
SELECT * FROM students WHERE name LIKE 'J____';
-- Any 4-letter name
SELECT * FROM students WHERE name LIKE '____';
Each underscore stands for one character. So J____ matches "John"
(J + 4 letters) but not "Jo" (too short) or "Jonathan" (too long).
Case Sensitivity Note
In SQLite, LIKE is case-insensitive for ASCII characters by default. That means
LIKE 'a%' will match both "Amina" and "amina". Other databases like
PostgreSQL behave differently, so always check if you switch systems.