From the course: MySQL Essential Training (2019)

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Substrings

Substrings

- [Instructor] You may perform simple substring operations in MySQL using the substring function. So I can say select substring of, and I'll give it a string, this is a string and I'll say six. And this will give me the part of the string starting from the sixth position to the end of the string. So when I execute this, I get is a string. So if we count them, one, two, three, four, so these start at one, they do not start at zero, five and then six. So six is the first character past the space. This is four, the space is five and the I is the sixth position. So that gives us is a string. Substr, without the ing is an alias for substring and so that works exactly the same way. You can also specify how many characters to return. So if I only want the first four characters after position six, then I can execute that and I get is a, which is just four characters long. You can count from the end of the string and just get the last six characters, which would be the word string, by putting…

Contents