0
0
SQLquery~10 mins

SUBSTRING extraction in SQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to extract the first 3 characters from the column 'name'.

SQL
SELECT SUBSTRING(name, 1, [1]) AS short_name FROM employees;
Drag options to blanks, or click blank then click option'
A10
B5
C0
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 as length returns an empty string.
Starting position other than 1 extracts from wrong place.
2fill in blank
medium

Complete the code to extract 4 characters starting from the 2nd character in 'address'.

SQL
SELECT SUBSTRING(address, [1], 4) AS part_address FROM locations;
Drag options to blanks, or click blank then click option'
A2
B1
C3
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 as start position causes errors.
Confusing length with start position.
3fill in blank
hard

Fix the error in the code to correctly extract 5 characters starting from the 3rd character in 'description'.

SQL
SELECT SUBSTRING(description, 3, [1]) AS snippet FROM products;
Drag options to blanks, or click blank then click option'
A3
B5
C7
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using zero length returns empty string.
Using length less than needed extracts incomplete substring.
4fill in blank
hard

Fill both blanks to extract 2 characters starting from the 4th character in 'code'.

SQL
SELECT SUBSTRING(code, [1], [2]) AS part_code FROM items;
Drag options to blanks, or click blank then click option'
A4
B2
C3
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping start position and length.
Using length larger than string length.
5fill in blank
hard

Fill all three blanks to extract the last 3 characters from 'serial_number' assuming length is 10.

SQL
SELECT SUBSTRING(serial_number, [1], [2]) AS last_three FROM devices WHERE LENGTH(serial_number) = [3];
Drag options to blanks, or click blank then click option'
A8
B3
C10
D7
Attempts:
3 left
💡 Hint
Common Mistakes
Starting at position 7 extracts 4 characters if length is 3.
Using wrong length in WHERE clause.