0
0
MySQLquery~20 mins

LOCATE and INSTR in MySQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
LOCATE and INSTR Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Find position of substring using LOCATE
What is the output of this query?

SELECT LOCATE('cat', 'concatenate');
MySQL
SELECT LOCATE('cat', 'concatenate');
A5
B4
C3
D0
Attempts:
2 left
💡 Hint
LOCATE returns the position where the substring starts, counting from 1.
query_result
intermediate
2:00remaining
Difference between LOCATE and INSTR
What is the output of this query?

SELECT INSTR('database', 'a');
MySQL
SELECT INSTR('database', 'a');
A0
B1
C2
D3
Attempts:
2 left
💡 Hint
INSTR returns the position of the first occurrence of the substring, starting at 1.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in LOCATE usage
Which option contains a syntax error when using LOCATE in MySQL?
ASELECT LOCATE('test');
BSELECT LOCATE('test', 'testing', 2);
CSELECT LOCATE('test', 'testing');
DSELECT LOCATE('test', 'testing', 0);
Attempts:
2 left
💡 Hint
LOCATE requires at least two arguments: substring and string.
query_result
advanced
2:00remaining
LOCATE with start position parameter
What is the output of this query?

SELECT LOCATE('a', 'banana', 3);
MySQL
SELECT LOCATE('a', 'banana', 3);
A4
B2
C3
D0
Attempts:
2 left
💡 Hint
The search starts at position 3 in the string.
🧠 Conceptual
expert
2: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');
A1
BNULL
C-1
D0
Attempts:
2 left
💡 Hint
INSTR returns 0 if the substring is not found.