Challenge - 5 Problems
Pattern Matching Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Case-sensitive pattern matching with LIKE
Given a table
Assume the table contains names: 'John', 'john', 'Joanna', 'joey', 'Joseph'.
employees with a column name, what will be the output of this query?SELECT name FROM employees WHERE name LIKE 'Jo%';Assume the table contains names: 'John', 'john', 'Joanna', 'joey', 'Joseph'.
PostgreSQL
SELECT name FROM employees WHERE name LIKE 'Jo%';
Attempts:
2 left
💡 Hint
LIKE is case-sensitive in PostgreSQL.
✗ Incorrect
The LIKE operator matches patterns with case sensitivity. Only names starting with uppercase 'Jo' match: 'John', 'Joanna', 'Joseph'.
❓ query_result
intermediate2:00remaining
Case-insensitive pattern matching with ILIKE
Using the same
Assume the same names as before.
employees table, what will this query return?SELECT name FROM employees WHERE name ILIKE 'jo%';Assume the same names as before.
PostgreSQL
SELECT name FROM employees WHERE name ILIKE 'jo%';
Attempts:
2 left
💡 Hint
ILIKE ignores case differences.
✗ Incorrect
ILIKE matches patterns ignoring case, so all names starting with 'jo' or 'Jo' are returned.
📝 Syntax
advanced2:00remaining
Identify the syntax error in pattern matching
Which option contains a syntax error in the pattern matching query?
Attempts:
2 left
💡 Hint
Look for unbalanced quotes in the SQL statements.
✗ Incorrect
Option B is missing the closing single quote for the LIKE pattern string 'C%_', causing a syntax error (unclosed string literal). The other options have properly closed strings.
❓ optimization
advanced2:00remaining
Optimizing pattern matching queries
Which query is the most efficient to find names starting with 'Ann' in a large
users table?Attempts:
2 left
💡 Hint
Consider how indexes work with pattern matching.
✗ Incorrect
LIKE with a fixed prefix (no leading wildcard) can use indexes efficiently. ILIKE and LOWER(name) prevent index use. Leading wildcard disables index use.
🧠 Conceptual
expert2:00remaining
Understanding ESCAPE clause in LIKE patterns
Which query correctly searches for names containing the literal underscore character '_' in a
customers table?Attempts:
2 left
💡 Hint
Underscore is a wildcard for one character unless escaped.
✗ Incorrect
Option C uses ESCAPE clause to treat backslash as escape character, so '\_' matches literal underscore. Option C lacks ESCAPE clause, so '\' is treated literally, causing no match. Option C matches any single character, not underscore. Option C uses brackets which is not standard in PostgreSQL LIKE.