Skip to main content
SQL โ€ข LESSON 138

SUBSTRING

How can we extract the first 5 characters of an email address?

Advancedโฑ 3 Minutesโญ 1510 XP
๐Ÿค” THE QUESTION

How can we extract the first 5 characters of an email address?

๐Ÿ’ก WHAT IS IT?

SUBSTRING(str, start, length) extracts a portion of a string based on 1-based start index and length.

๐ŸŽฏ WHAT IS IT USED FOR?

Extracting area codes, parsing prefix codes, masking sensitive PII fields.

๐Ÿ’ป EXAMPLE
SELECT
SUBSTRING(email, 1, 5) AS email_prefix
FROM employees;

๐ŸŽฏ Mission Objectives

Practice typing production-grade SQL code for SUBSTRING.

  • โœ“ SUBSTRING()
  • โœ“ String slicing
  • โœ“ Prefix extraction
  • โœ“ PII masking