From the course: SQL: Data Reporting and Analysis

Unlock the full course today

Join today to access over 24,900 courses taught by industry experts.

More advanced string functions

More advanced string functions - SQL Tutorial

From the course: SQL: Data Reporting and Analysis

More advanced string functions

- [Instructor] Recently, we've used left and right to return parts of string from the beginning or end, respectively. But what if you wanted to return a partial string from the middle? Here we could use substring unless you're using Oracle, in which case you need substra. Substra works in all of the four versions except Microsoft. So none of them work across the board. Anyway, we're going to use substring. Select substring, first name, and this one takes three arguments. 1,1, like that. To get the first letter of the first name, we give the field name then the starting character one, not zero. And then the length, the number of characters we want to return. So this should return us the same as left, 1 returns us, and you can see it does 'cause there's our P. Now let's play around with this a little bit. What if we tried 1,2, then we'd have PE for Penelope instead of P because we've said that we still want to start…

Contents