The SUBSTRING_INDEX function in MySQL is used to extract a substring from a given string. It returns the part of the string before or after a specified delimiter.
Syntax:
SUBSTRING_INDEX(string,delimiter,count)
Parameters:
- string: The original string from which you want to extract a substring.
- delimiter: The character or string that separates the parts of the string.
- count: An integer value that determines how many times the delimiter appears in the string.
Example:
SELECT SUBSTRING_INDEX(‘www.example.com’, ‘.’, 2)
Output:
www.example