0
0
SQLquery~20 mins

SUBSTRING extraction in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Substring Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Extracting a substring from a string
Given a table Employees with a column FullName containing full names, which SQL query extracts the first 4 characters of each name?
SQL
SELECT FullName FROM Employees;
ASELECT SUBSTRING(FullName, 0, 4) FROM Employees;
BSELECT SUBSTRING(FullName, 1, 4) FROM Employees;
CSELECT SUBSTRING(FullName, 1, 5) FROM Employees;
DSELECT SUBSTR(FullName, 2, 4) FROM Employees;
Attempts:
2 left
💡 Hint
Remember that SQL substring positions start at 1, not 0.
query_result
intermediate
2:00remaining
Extracting domain from email addresses
Given a table Users with a column Email containing email addresses, which query extracts the domain part (after '@') correctly?
SQL
SELECT Email FROM Users;
ASELECT SUBSTRING(Email, CHARINDEX('@', Email), LEN(Email)) FROM Users;
BSELECT SUBSTRING(Email, 1, CHARINDEX('@', Email) - 1) FROM Users;
CSELECT SUBSTRING(Email, CHARINDEX('@', Email) + 2, LEN(Email)) FROM Users;
DSELECT SUBSTRING(Email, CHARINDEX('@', Email) + 1, LEN(Email)) FROM Users;
Attempts:
2 left
💡 Hint
The domain starts right after the '@' character.
📝 Syntax
advanced
2:00remaining
Identifying syntax error in SUBSTRING usage
Which of the following SQL queries will cause a syntax error?
ASELECT SUBSTRING(Name FROM 2 FOR 3) FROM Customers;
BSELECT SUBSTRING(Name, 2, 3) FROM Customers;
CSELECT SUBSTRING(Name, 2, 3, 4) FROM Customers;
DSELECT SUBSTRING(Name, 2) FROM Customers;
Attempts:
2 left
💡 Hint
Check the number of arguments SUBSTRING accepts in standard SQL.
optimization
advanced
2:00remaining
Optimizing substring extraction for performance
You want to extract the first 3 characters of a column Code from a large table Products. Which query is generally more efficient in SQL Server?
ASELECT LEFT(Code, 3) FROM Products;
BSELECT SUBSTRING(Code, 1, 3) FROM Products;
CSELECT RIGHT(Code, LEN(Code) - 3) FROM Products;
DSELECT SUBSTRING(Code, 0, 3) FROM Products;
Attempts:
2 left
💡 Hint
Consider built-in functions optimized for common tasks.
🧠 Conceptual
expert
2:00remaining
Understanding SUBSTRING behavior with out-of-range positions
What is the result of this query if the Name column contains 'Amy' (3 characters)? SELECT SUBSTRING(Name, 5, 3) FROM People;
SQL
SELECT SUBSTRING(Name, 5, 3) FROM People WHERE Name = 'Amy';
AAn empty string ('')
BNULL
CA syntax error
DThe entire string 'Amy'
Attempts:
2 left
💡 Hint
What happens if the start position is beyond the string length?