The SQL SUBSTRING() function is used to return part of text or characters of a text. The substring will accept 3 parameters as below:
SUBSTRING ( expression ,start , length )
Example Customer Table
The following data table is for example only. Let's use SUBSTRING() function to return the first 4 characters from a customer table. The column we going to use are the Name column.
ID | Name | Age |
1 | Thomas Anderson | 45 |
2 | Andrew Golden | 38 |
3 | Ken Tom | 30 |
4 | Andrew Golden | 36 |
5 | Timothy Kirk | 32 |
6 | Kelly Smith | 39 |
Example of Running SQL Query
SELECT SUBSTRING(Name, 1, 4) AS Name_Part FROM Customers
After running the above query, it will return the following result.
Name_Part |
Thom |
Andr |
Ken |
Andr |
Timo |
Kell |