Curriculum
Course: MYSQL
Login

Curriculum

MYSQL

MySQL References

0/140
Text lesson

SUBSTRING_INDEX

Example

Provide a portion of a string preceding a specified number of occurrences of a delimiter.

SELECT SUBSTRING_INDEX(“www.w3schools.com”“.”, 1); 

Definition and Usage

The SUBSTRING_INDEX() function retrieves a substring from a string, occurring before a specified number of delimiter instances.

Syntax

SUBSTRING_INDEX(stringdelimiternumber)

Parameter Values

Parameter

Description

string

Mandatory. Refers to the original string.

delimiter

Necessary. Specifies the delimiter to locate.

number

Mandatory. Indicates the number of occurrences to search for the delimiter. Can be either positive or negative. For a positive number, the function returns all text to the left of the delimiter. For a negative number, it returns all text to the right of the delimiter.

Technical Details

Works in: From MySQL 4.0

More Examples

Example

Provide a substring of a string occurring before a specified count of delimiter instances.

SELECT SUBSTRING_INDEX(“www.w3schools.com”“.”2);