SQL MID Function


The MID function is used to extract substrings from column values of string type in a table.

Syntax

SELECT MID(column_name,start ,length) AS some_name FROM table_name;
Parameter Description
column_name Required. The field to extract characters from
start Required. Specifies the starting position (starts at 1)
length Optional. The number of characters to return. If omitted, the MID() function returns the rest of the text

Example

student Table

stud_sidstud_nameBranch
11211Ashwani SinghECE
11212Sachin YadavCSE
11213DeepakMECH
SELECT MID(stud_name,3,5) AS shortname FROM student;
Output
shortname
shwan
achin
eepak

Share this article on