Challenge - 5 Problems
LIKE Pattern Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Find names starting with 'Jo' using LIKE
Given a table users with a column
name, which query returns all names starting with 'Jo'?MySQL
SELECT name FROM users WHERE name LIKE 'Jo%';
Attempts:
2 left
💡 Hint
Use % to match any sequence of characters after 'Jo'.
✗ Incorrect
The pattern 'Jo%' matches any string starting with 'Jo'. '%Jo' matches strings ending with 'Jo'. '_Jo%' requires one character before 'Jo'. 'Jo_' matches strings starting with 'Jo' and exactly one more character.
❓ query_result
intermediate2:00remaining
Match emails ending with '.com'
Which query returns all emails ending with '.com' from the
contacts table?MySQL
SELECT email FROM contacts WHERE email LIKE '%.com';
Attempts:
2 left
💡 Hint
Use % before '.com' to match any characters before the ending.
✗ Incorrect
The pattern '%.com' matches any string ending with '.com'. '.com%' matches strings starting with '.com'. '%com.' matches strings ending with 'com.'. '%com' matches strings ending with 'com' but not necessarily with a dot.
📝 Syntax
advanced2:00remaining
Identify the syntax error in LIKE pattern
Which option contains a syntax error in the LIKE pattern?
MySQL
SELECT * FROM products WHERE code LIKE 'A_%%';
Attempts:
2 left
💡 Hint
Check if the pattern uses valid wildcard characters.
✗ Incorrect
The pattern 'A_%%' is invalid because '%%' is not a valid wildcard sequence. '%' is the wildcard for any sequence of characters, and '_' is for a single character. Double % is redundant and causes syntax error.
❓ query_result
advanced2:00remaining
Find rows where name contains 'an' anywhere
Which query returns all rows from
employees where the name contains the substring 'an' anywhere?MySQL
SELECT * FROM employees WHERE name LIKE '%an%';
Attempts:
2 left
💡 Hint
Use % before and after 'an' to match anywhere in the string.
✗ Incorrect
'%an%' matches any string containing 'an' anywhere. 'an%' matches strings starting with 'an'. '_an%' matches strings with any single character before 'an'. '%an' matches strings ending with 'an'.
🧠 Conceptual
expert3:00remaining
Understanding escape characters in LIKE patterns
You want to find rows where the column
code contains the literal underscore character '_'. Which query correctly finds these rows?Attempts:
2 left
💡 Hint
Use ESCAPE clause to treat underscore as a normal character.
✗ Incorrect
In LIKE, underscore '_' is a wildcard for any single character. To match a literal underscore, you must escape it. Option C uses ESCAPE '\' to treat '\_' as a literal underscore. Option C tries to escape but lacks ESCAPE clause, so it won't work. Option C matches any single character. Option C is invalid syntax in MySQL.