SUBSTRING
Returns a substring that starts at the given position.
MySQL 8.4
SUBSTRING(str, pos[, len])- [ ]optional part
- str
- Source stringVARCHAR
- pos
- Start position, counting from 1; a negative one counts from the end of the stringINT
- len
- Length of the substring, up to the end of the string by defaultINTOptional
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.4
SELECT SUBSTRING('sql-academy', 5);Substring of a given length
MySQL 8.4
SELECT SUBSTRING('sql-academy', 1, 3);Position counted from the end
MySQL 8.4
SELECT SUBSTRING('sql-academy', -3);Details
The same function is available as SUBSTR and in the standard form SUBSTRING(str FROM pos FOR len).