Recall & Review
beginner
What does the SUBSTRING function do in MySQL?
SUBSTRING extracts a part of a string starting from a specified position for a given length.
Click to reveal answer
beginner
How does the LEFT function work in MySQL?
LEFT returns the leftmost characters from a string, based on the number of characters you specify.
Click to reveal answer
intermediate
What is the difference between SUBSTRING and LEFT functions?
SUBSTRING can start extracting from any position in the string, while LEFT always starts from the beginning (left side).
Click to reveal answer
beginner
How does the RIGHT function work in MySQL?
RIGHT returns the rightmost characters from a string, based on the number of characters you specify.
Click to reveal answer
beginner
Write a MySQL query to get the first 5 characters of the string 'HelloWorld'.
SELECT LEFT('HelloWorld', 5); -- This returns 'Hello'
Click to reveal answer
What will SUBSTRING('Database', 3, 4) return?
✗ Incorrect
SUBSTRING starts at position 3 and takes 4 characters: 'taba'.
Which function extracts characters from the right side of a string?
✗ Incorrect
RIGHT extracts characters from the right end of the string.
What does LEFT('OpenAI', 3) return?
✗ Incorrect
LEFT returns the first 3 characters from the left: 'Ope'.
If you want to extract characters starting from the 2nd character to the end, which function and syntax is correct?
✗ Incorrect
SUBSTRING(string, 2) extracts from the 2nd character to the end.
What will RIGHT('Database', 4) return?
✗ Incorrect
RIGHT returns the last 4 characters: 'base'.
Explain how to use SUBSTRING, LEFT, and RIGHT functions to extract parts of a string in MySQL.
Think about where you want to start and how many characters you want.
You got /4 concepts.
Describe a real-life scenario where you might use LEFT or RIGHT functions in a database query.
Consider common string parts like prefixes or suffixes.
You got /3 concepts.