Beginner

246. POSITION Function

Learn how to find the position of one string within another string.

📘 Lesson 246 of 728 ⏱ 9 min 🎯 Intermediate

The POSITION function searches for a substring inside another string and returns its position when supported by the database.

Finding the location of a character or substring is useful when parsing structured text fields.

Find the position of the @ character in an email address.

SQL
SELECT
    Email,
    POSITION('@' IN Email) AS AtPosition
FROM Customers;

POSITION is useful for parsing email addresses, codes, identifiers, and structured text.

  • POSITION searches for a substring.
  • It returns the location of the match.
  • It is useful for parsing text.
  • Syntax varies between databases.
  • It can be combined with SUBSTRING.
What does POSITION do?

POSITION finds the location of a substring within another string.

How can POSITION help parse an email?

It can locate the @ symbol so the email address can be split into different parts.

Have you finished this lesson?

Introduction to SQL – All Lessons