0
0
SQLquery~20 mins

WHERE with LIKE pattern matching in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
LIKE Pattern Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Find names starting with 'Jo' using LIKE
Given a table Employees with a column name, which query returns all employees whose names start with 'Jo'?
SQL
SELECT name FROM Employees WHERE name LIKE 'Jo%';
ASELECT name FROM Employees WHERE name LIKE '%Jo%';
BSELECT name FROM Employees WHERE name LIKE '%Jo';
CSELECT name FROM Employees WHERE name LIKE 'J_o%';
DSELECT name FROM Employees WHERE name LIKE 'Jo%';
Attempts:
2 left
💡 Hint
The percent sign (%) matches any sequence of characters, and placing it after 'Jo' means names starting with 'Jo'.
query_result
intermediate
2:00remaining
Select emails containing 'admin' anywhere
Which SQL query returns all rows from Users where the email contains the word 'admin' anywhere in the string?
SQL
SELECT email FROM Users WHERE email LIKE '%admin%';
ASELECT email FROM Users WHERE email LIKE '%admin';
BSELECT email FROM Users WHERE email LIKE '%admin%';
CSELECT email FROM Users WHERE email LIKE 'admin%';
DSELECT email FROM Users WHERE email LIKE '_admin%';
Attempts:
2 left
💡 Hint
Use % before and after 'admin' to find it anywhere in the string.
📝 Syntax
advanced
2:00remaining
Identify the query with syntax error in LIKE pattern
Which SQL query will cause a syntax error due to incorrect LIKE pattern?
ASELECT * FROM Orders WHERE order_id LIKE '12%3_'
BSELECT * FROM Orders WHERE order_id LIKE '123%';
CSELECT * FROM Orders WHERE order_id LIKE '12_3%';
DSELECT * FROM Orders WHERE order_id LIKE '%123';
Attempts:
2 left
💡 Hint
Check for missing quotes or incomplete strings in the LIKE pattern.
optimization
advanced
2:00remaining
Optimize query using LIKE for prefix search
You want to find all customers whose city starts with 'San'. Which query is most efficient for this search?
ASELECT * FROM Customers WHERE city LIKE '%San';
BSELECT * FROM Customers WHERE city LIKE '%San%';
CSELECT * FROM Customers WHERE city LIKE 'San%';
DSELECT * FROM Customers WHERE city LIKE '_San%';
Attempts:
2 left
💡 Hint
Using a pattern that starts with the search string allows index use.
🧠 Conceptual
expert
3:00remaining
Understanding LIKE pattern matching with escape characters
Given a table Files with a column filename, which query correctly finds all files with names ending with '_backup' (underscore is a literal character, not a wildcard)?
ASELECT filename FROM Files WHERE filename LIKE '%\_backup' ESCAPE '\';
BSELECT filename FROM Files WHERE filename LIKE '%[_]backup';
CSELECT filename FROM Files WHERE filename LIKE '%_backup';
DSELECT filename FROM Files WHERE filename LIKE '%\_backup';
Attempts:
2 left
💡 Hint
Use ESCAPE clause to treat underscore as a normal character.