SUBSTRING
Returns a substring that starts at the given position.
MySQL 8.1
SUBSTRING(str, pos[, len])Parameters
- strVARCHAR
- Source string
- posINT
- Start position of the substring, a negative one counts from the end of the string
- lenINToptional
- Length of the substring, up to the end of the string by default
Return value
A substring; an empty string if pos is 0 or greater than the string length, or len is less than 1
Examples
Rest of the string from a position
MySQL 8.1
SELECT SUBSTRING('sql-academy', 5);Substring of a given length
MySQL 8.1
SELECT SUBSTRING('sql-academy', 1, 3);Position counted from the end
MySQL 8.1
SELECT SUBSTRING('sql-academy', -3);Details
The same function is available as SUBSTR and in the standard form SUBSTRING(str FROM pos FOR len).