0
0
PostgreSQLquery~20 mins

Pattern matching with LIKE and ILIKE in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Pattern Matching Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Case-sensitive pattern matching with LIKE
Given a table 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%';
AJohn, Joanna, Joseph
Bjohn, joey
CJohn, john, Joanna, joey, Joseph
DNo rows returned
Attempts:
2 left
💡 Hint
LIKE is case-sensitive in PostgreSQL.
query_result
intermediate
2:00remaining
Case-insensitive pattern matching with ILIKE
Using the same 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%';
AJohn, Joanna, Joseph
Bjohn, joey
CNo rows returned
DJohn, john, Joanna, joey, Joseph
Attempts:
2 left
💡 Hint
ILIKE ignores case differences.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in pattern matching
Which option contains a syntax error in the pattern matching query?
ASELECT * FROM products WHERE code LIKE 'B%_2';
BSELECT * FROM products WHERE code LIKE 'C%_';
CSELECT * FROM products WHERE code LIKE 'D%_2' ESCAPE '\';
DSELECT * FROM products WHERE code LIKE 'A_1%';
Attempts:
2 left
💡 Hint
Look for unbalanced quotes in the SQL statements.
optimization
advanced
2:00remaining
Optimizing pattern matching queries
Which query is the most efficient to find names starting with 'Ann' in a large users table?
ASELECT * FROM users WHERE name LIKE 'Ann%';
BSELECT * FROM users WHERE name ILIKE 'ann%';
CSELECT * FROM users WHERE LOWER(name) LIKE 'ann%';
DSELECT * FROM users WHERE name LIKE '%Ann%';
Attempts:
2 left
💡 Hint
Consider how indexes work with pattern matching.
🧠 Conceptual
expert
2:00remaining
Understanding ESCAPE clause in LIKE patterns
Which query correctly searches for names containing the literal underscore character '_' in a customers table?
ASELECT * FROM customers WHERE name LIKE '%[_]%';
BSELECT * FROM customers WHERE name LIKE '%\_%';
CSELECT * FROM customers WHERE name LIKE '%\_%' ESCAPE '\';
DSELECT * FROM customers WHERE name LIKE '%_%';
Attempts:
2 left
💡 Hint
Underscore is a wildcard for one character unless escaped.