What does the SQL LIKE operator do in a WHERE clause?
The LIKE operator is used to search for a specified pattern in a column. It helps filter rows where the column's value matches the pattern.
Click to reveal answer
beginner
What wildcard characters are commonly used with LIKE in SQL?
The two main wildcards are: - % which matches zero or more characters - _ which matches exactly one character
Click to reveal answer
beginner
Write a simple SQL query to find all customers whose name starts with 'A'.
Example query: SELECT * FROM customers WHERE name LIKE 'A%'; This finds all names beginning with 'A'.
Click to reveal answer
intermediate
How does LIKE '%abc%' differ from LIKE 'abc%'?
LIKE '%abc%' finds any value containing 'abc' anywhere. LIKE 'abc%' finds values starting with 'abc'.
Click to reveal answer
intermediate
Can LIKE be case sensitive?
It depends on the database system and collation settings. For example, in MySQL, LIKE is case-insensitive by default, but in PostgreSQL it is case-sensitive.
Click to reveal answer
Which wildcard matches exactly one character in a SQL LIKE pattern?
A_
B*
C%
D#
✗ Incorrect
The underscore (_) matches exactly one character in a pattern.
What does the pattern '%book%' match in a LIKE clause?
AValues containing 'book' anywhere
BValues ending with 'book'
CValues starting with 'book'
DValues exactly equal to 'book'
✗ Incorrect
The percent signs (%) before and after 'book' mean it can appear anywhere in the value.
Which SQL query finds rows where the column 'city' starts with 'New'?
ASELECT * FROM table WHERE city LIKE '%New';
BSELECT * FROM table WHERE city LIKE 'New%';
CSELECT * FROM table WHERE city LIKE '_New%';
DSELECT * FROM table WHERE city LIKE '%New%';
✗ Incorrect
The pattern 'New%' matches values starting with 'New'.
If you want to find all rows where a column contains exactly 3 characters, which pattern would you use?
ALIKE '%'
BLIKE '___%'
CLIKE '___'
DLIKE '_'
✗ Incorrect
Three underscores (_) mean exactly three characters.
In which case is LIKE case-sensitive by default?
AMySQL
BOracle
CSQLite
DPostgreSQL
✗ Incorrect
PostgreSQL's LIKE operator is case-sensitive by default.
Explain how the SQL LIKE operator works with wildcards in a WHERE clause.
Think about how you search for words containing or starting with certain letters.
You got /3 concepts.
Describe a scenario where you would use LIKE '%abc%' versus LIKE 'abc%' in a query.
Consider searching for a substring anywhere or only at the beginning.
You got /3 concepts.
Practice
(1/5)
1. Which SQL clause is used to filter rows based on a pattern in a text column? SELECT * FROM employees WHERE name LIKE 'A%';
easy
A. GROUP BY
B. ORDER BY
C. WHERE with LIKE
D. JOIN
Solution
Step 1: Understand the purpose of LIKE
The LIKE keyword is used to match text patterns in SQL queries.
Step 2: Identify the filtering clause
The WHERE clause filters rows, and combined with LIKE, it filters rows matching a pattern.
Final Answer:
WHERE with LIKE -> Option C
Quick Check:
WHERE with LIKE = B [OK]
Hint: LIKE is always used with WHERE to filter text patterns [OK]
Common Mistakes:
Confusing LIKE with GROUP BY
Using LIKE without WHERE
Thinking ORDER BY filters rows
2. Which of the following is the correct syntax to find names starting with 'Jo' in a table called users?
easy
A. SELECT * FROM users WHERE name LIKE '%Jo';
B. SELECT * FROM users WHERE name LIKE 'Jo%';
C. SELECT * FROM users WHERE name LIKE '_Jo%';
D. SELECT * FROM users WHERE name LIKE 'Jo_';
Solution
Step 1: Understand the pattern for names starting with 'Jo'
Names starting with 'Jo' means 'Jo' followed by any characters, so pattern is 'Jo%'.
Step 2: Match the correct syntax
SELECT * FROM users WHERE name LIKE 'Jo%'; uses LIKE 'Jo%' which matches names starting with 'Jo'. Others do not match this pattern.
Final Answer:
SELECT * FROM users WHERE name LIKE 'Jo%'; -> Option B
Quick Check:
Start with 'Jo' = LIKE 'Jo%' [OK]
Hint: Use % after text to match any ending characters [OK]
Common Mistakes:
Using % before text to match start
Using _ instead of %
Misplacing wildcards
3. Given the table products with a column product_code, what rows will this query return?
SELECT * FROM products WHERE product_code LIKE '_A%';
medium
A. Rows where product_code starts with 'A'
B. Rows where product_code ends with 'A'
C. Rows where product_code contains 'A' anywhere
D. Rows where product_code has 'A' as the second character
Solution
Step 1: Understand the pattern '_A%'
The underscore (_) matches exactly one character, so the first character can be anything. 'A' is the second character. '%' means any characters after.
Step 2: Interpret the query result
The query returns rows where the second character of product_code is 'A', regardless of the first character or what follows.
Final Answer:
Rows where product_code has 'A' as the second character -> Option D
Quick Check:
_A% means second char is 'A' [OK]
Hint: Use _ for single char, % for any chars [OK]
Common Mistakes:
Thinking _ matches zero or multiple characters
Confusing position of 'A' in pattern
Assuming LIKE matches anywhere without wildcards
4. Identify the error in this SQL query:
SELECT * FROM customers WHERE city LIKE '%York_';
It should find cities ending with 'York' followed by exactly one character.
medium
A. The pattern is correct; no error
B. The underscore should be before 'York' like '_%York'
C. The pattern should be '%York%' to match any after 'York'
D. The underscore should be after 'York' but without % like '%York_'
Solution
Step 1: Analyze the pattern '%York_'
The % matches any characters before 'York', then 'York' literal, then _ matches exactly one character after.
Step 2: Check if it matches cities ending with 'York' plus one char
This pattern correctly matches cities ending with 'York' plus exactly one character, so the query is correct.
Final Answer:
The pattern is correct; no error -> Option A
Quick Check:
'%York_' matches 'York' + 1 char [OK]
Hint: Check if _ and % are placed as intended [OK]
Common Mistakes:
Thinking _ matches multiple characters
Confusing placement of % and _
Assuming pattern must end with %
5. You want to find all employees whose email ends with '.com' but have exactly one character before '.com'. Which query is correct?
hard
A. SELECT * FROM employees WHERE email LIKE '%_.com';
B. SELECT * FROM employees WHERE email LIKE '%_.com%';
C. SELECT * FROM employees WHERE email LIKE '%.__.com';
D. SELECT * FROM employees WHERE email LIKE '%.com';
Solution
Step 1: Understand the requirement
The email should end with '.com' and have exactly one character before '.com'.
Step 2: Analyze each pattern
SELECT * FROM employees WHERE email LIKE '%.com'; matches any email ending with '.com' but no restriction on characters before. SELECT * FROM employees WHERE email LIKE '%_.com'; uses '%_.com' meaning any characters, then exactly one character, then '.com' at the end. SELECT * FROM employees WHERE email LIKE '%.__.com'; expects two characters before '.com' which is incorrect. SELECT * FROM employees WHERE email LIKE '%_.com%'; allows any characters after '.com' which is incorrect for ending.
Final Answer:
SELECT * FROM employees WHERE email LIKE '%_.com'; -> Option A
Quick Check:
Use _ before '.com' for exactly one char [OK]
Hint: Use _ before '.com' to match exactly one char [OK]
Common Mistakes:
Using % instead of _ for single character
Placing % after '.com' allowing extra chars
Miscounting characters before '.com'
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.