In MySQL, the SUBSTRING()
(or SUBSTR()
) function supports negative values for the starting position.
SUBSTRING(string, start, length)
-- or
SUBSTR(string, start, length)
string
: The source string.start
: The starting position (1-based index).length
: (Optional) Number of characters to extract.SELECT SUBSTRING('Hello World', 7, 5);
-- or
SELECT SUBSTR('Hello World', 7, 5);
Result:
World
SELECT SUBSTRING('abcdef', 3);
-- or
SELECT SUBSTR('abcdef', 3);
Result:
cdef