bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/SQL/SQL References
SQL•SQL References

MySQL SUBSTRING_INDEX() Function

Concept visual

MySQL SUBSTRING_INDEX() Function

Pointer walk
two pointers
leftright102132436485116
left=0
right=6
1
3

Start at both ends

Example

Return a substring of a string before a specified number of delimiter occurs:

SELECT SUBSTRING_INDEX("www.w3schools.com", ".", 1);

Definition and Usage

The SUBSTRING_INDEX() function returns a substring of a string before a specified number of delimiter occurs.

Syntax

SUBSTRING_INDEX( string, delimiter, number )

Parameter Values

Parameter

Description string

Required. The original string delimiter Required. The delimiter to search for number Required. The number of times to search for the delimiter. Can be both a positive or negative number. If it is a positive number, this function returns all to the left of the delimiter. If it is a negative number, this function returns all to the right of the delimiter.

Technical Details

Works in:

From MySQL 4.0

More Examples

Example

Return a substring of a string before a specified number of delimiter occurs:

SELECT SUBSTRING_INDEX("www.w3schools.com", ".", 2);

Previous

❮ MySQL Functions

Next

Previous

MySQL SUBSTRING() Function

Next

MySQL TRIM() Function