SQL MID() is used to extract characters from a text field.
Syntaxt
SELECT MID(column_name,start,length) FROM table_name
Table – Users
+—–+——-+
| uid | name |
+—–+——-+
| 1 | name1 |
| 2 | name2 |
| 3 | name3 |
| 4 | name4 |
+—–+——-+
Example
mysql> SELECT MID(name,1,3) as name FROM users;
+——+
| name |
+——+
| nam |
| nam |
| nam |
| nam |
+——+
4 rows in set (0.00 sec)
mysql> SELECT MID(name,2,4) as name FROM users;
+——+
| name |
+——+
| ame1 |
| ame2 |
| ame3 |
| ame4 |
+——+
4 rows in set (0.00 sec)