SQL MID() Function

The MID() Function

The MID() work is utilized to remove characters from a content field.

SQL MID() Syntax

SELECT MID(column_name,start,length) AS some_name FROM table_name;
Parameter Description
column_name Required. The field to extricate characters from
start Required. Determines the beginning position (begins at 1)
length Optional. The quantity of characters to return. Whenever excluded, the MID() work restores whatever is left of the text

Note: The equal capacity for SQL Server is SUBSTRING():

SELECT SUBSTRING(column_name,start,length) AS some_name FROM table_name;


In this instructional exercise we will utilize the outstanding database.

Below is a determination from the "Clients" table:

CustomerID CustomerName Phone Address City Country

Ramonita Homan 231-596-2048 ORubaiyat Road Excellent Rapid MI USA
2 Charles L. Emmons 507-256-8113 Rosewood Court Clarks Grove MN USA
3 Ruth C. Dorsey Quay Street NAILBRIDGE YO4 5SS UK/td>

Evelyn B. Blacker 077 6011 6540 Wade Lane SAND HOLE YO4 5SS UK
5 Nytorpsv채gen 45 Christina Berglund Nytorpsv채gen 45 BANKERYD Sweden

SQL MID() Example

The following SQL explanation chooses the initial four characters from the "City" segment from the "Clients" table:


SELECT MID(City,1,4) AS ShortCity
FROM Customers;