Skip to main content
SQL • LESSON 138

SUBSTRING

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

Advanced3 Minutes1510 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