In MySQL, the SUBSTRING() (or SUBSTR()) function supports negative values for the starting position.


Syntax

Standard SQL

SUBSTRING(string, start, length)
-- or
SUBSTR(string, start, length)

Examples

1. Extracting a substring

SELECT SUBSTRING('Hello World', 7, 5);
-- or
SELECT SUBSTR('Hello World', 7, 5);

Result:

World


2. Without length (returns from start to end)

SELECT SUBSTRING('abcdef', 3);
-- or
SELECT SUBSTR('abcdef', 3);

Result:

cdef