Challenge - 5 Problems
LOCATE and INSTR Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Find position of substring using LOCATE
What is the output of this query?
SELECT LOCATE('cat', 'concatenate');MySQL
SELECT LOCATE('cat', 'concatenate');
Attempts:
2 left
💡 Hint
LOCATE returns the position where the substring starts, counting from 1.
✗ Incorrect
The substring 'cat' starts at the 4th character in 'concatenate'.
❓ query_result
intermediate2:00remaining
Difference between LOCATE and INSTR
What is the output of this query?
SELECT INSTR('database', 'a');MySQL
SELECT INSTR('database', 'a');
Attempts:
2 left
💡 Hint
INSTR returns the position of the first occurrence of the substring, starting at 1.
✗ Incorrect
The first 'a' in 'database' is at position 2.
📝 Syntax
advanced2:00remaining
Identify the syntax error in LOCATE usage
Which option contains a syntax error when using LOCATE in MySQL?
Attempts:
2 left
💡 Hint
LOCATE requires at least two arguments: substring and string.
✗ Incorrect
Option A is missing the second argument (the string to search in), causing a syntax error.
❓ query_result
advanced2:00remaining
LOCATE with start position parameter
What is the output of this query?
SELECT LOCATE('a', 'banana', 3);MySQL
SELECT LOCATE('a', 'banana', 3);
Attempts:
2 left
💡 Hint
The search starts at position 3 in the string.
✗ Incorrect
Starting from the 3rd character, the first 'a' appears at position 4.
🧠 Conceptual
expert2:00remaining
Behavior of INSTR when substring is not found
What is the output of this query?
SELECT INSTR('hello world', 'x');MySQL
SELECT INSTR('hello world', 'x');
Attempts:
2 left
💡 Hint
INSTR returns 0 if the substring is not found.
✗ Incorrect
Since 'x' is not in 'hello world', INSTR returns 0.