SUBSTRING(string,delimiter,count)

Syntax:

SUBSTRING(string,position[,length])
SUBSTRING(string FROM position[FOR length])

Description: Returns the portion of string starting at position characters from the left. If length is specified, no more than length characters will be returned.

Examples:

  • SUBSTRING('Howard Jacobs' FROM 4) returns ard Jacobs.

  • SUBSTRING('Howard Jacobs' FROM 4 FOR 2) returns ar.

  • SUBSTRING('Howard Jacobs',4,2) returns ar.

See also: LEFT(), MID(), RIGHT(), SUBSTRING_INDEX()

Get Sams Teach Yourself MySQL in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.