Provide a portion of a string preceding a specified number of occurrences of a delimiter.
SELECT SUBSTRING_INDEX(“www.w3schools.com”, “.”, 1); |
The SUBSTRING_INDEX() function retrieves a substring from a string, occurring before a specified number of delimiter instances.
SUBSTRING_INDEX(string, delimiter, number) |
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. |
Works in: | From MySQL 4.0 |
Provide a substring of a string occurring before a specified count of delimiter instances.
SELECT SUBSTRING_INDEX(“www.w3schools.com”, “.”, 2); |