MYSQL MID Function
Category : TECH Author : Ankur Rastogi Date : Sat Jun 04 2016 Views : 100

MYSQL MID Overview
MYSQL MID function is used to return a sub string characters from any text field column on the basis of start point and length of the sub string to return.
MID function takes three input
column_name => Name of the field from which sub string will be returned.
start => Starting point of substring to return.
length => Length of characters from start point to return.
MYSQL MID Syntax
Syntax for MYSQL MID function is
SELECT MID(column_name, start, length) FROM table_name;
MYSQL MID Example
Let us have a look at an example
Consider student_list table which contains student list.
+-----+------------------+--------+-----------+
| sid | name | year | hostel_id |
+-----+------------------+--------+-----------+
| 1 | Ankur Rastogi | First | 4 |
| 2 | Amit Kumar | Second | 8 |
| 3 | Ram Kumar | Second | 8 |
| 4 | Shiv Saxena | First | 6 |
| 5 | Aman Aggarwal | Third | 3 |
| 6 | Nipun Gupta | Fourth | 2 |
| 7 | Arpit Gupta | Third | 1 |
| 8 | Shantanu Rastogi | Second | 3 |
| 9 | Ramesh Kumar | Third | 1 |
| 10 | Neelima Dhingra | Second | NULL |
| 11 | Anu Sibbal | Third | NULL |
+-----+------------------+--------+-----------+
MYSQL MID Example Case 1:
Let us fetch first three letters of student's name.
SELECT MID(name,1,3) FROM student_list;
+---------------+
| MID(name,1,3) |
+---------------+
| Ank |
| Ami |
| Ram |
| Shi |
| Ama |
| Nip |
| Arp |
| Sha |
| Ram |
| Nee |
| Anu |
+---------------+

MYSQL MID Overview
MYSQL MID function is used to return a sub string characters from any text field column on the basis of start point and length of the sub string to return.
MID function takes three input
column_name => Name of the field from which sub string will be returned.
start => Starting point of substring to return.
length => Length of characters from start point to return.
MYSQL MID Syntax
Syntax for MYSQL MID function is
SELECT MID(column_name, start, length) FROM table_name;
MYSQL MID Example
Let us have a look at an example
Consider student_list table which contains student list.
+-----+------------------+--------+-----------+
| sid | name | year | hostel_id |
+-----+------------------+--------+-----------+
| 1 | Ankur Rastogi | First | 4 |
| 2 | Amit Kumar | Second | 8 |
| 3 | Ram Kumar | Second | 8 |
| 4 | Shiv Saxena | First | 6 |
| 5 | Aman Aggarwal | Third | 3 |
| 6 | Nipun Gupta | Fourth | 2 |
| 7 | Arpit Gupta | Third | 1 |
| 8 | Shantanu Rastogi | Second | 3 |
| 9 | Ramesh Kumar | Third | 1 |
| 10 | Neelima Dhingra | Second | NULL |
| 11 | Anu Sibbal | Third | NULL |
+-----+------------------+--------+-----------+
MYSQL MID Example Case 1:
Let us fetch first three letters of student's name.
SELECT MID(name,1,3) FROM student_list;
+---------------+
| MID(name,1,3) |
+---------------+
| Ank |
| Ami |
| Ram |
| Shi |
| Ama |
| Nip |
| Arp |
| Sha |
| Ram |
| Nee |
| Anu |
+---------------+
Disclaimer: The above content reflect author’s personal views and do not reflect the views of OYEWIKI. Neither OYEWIKI nor any person/organization acting on its behalf is liable to accept any legal liability/responsibility for any error/mislead in this information or any information available on the website. This website in no way accepts the responsibility for any loss, injury, damage, discomfort or inconvenience caused as a result of reliance on any information provided on this website.
If you want to add more comments to the article or you see any thing incorrect please write a comment below and we will surely get back to you.