Code has been added to clipboard!

How to Use SQL MID

Reading time 1 min
Published Aug 9, 2017
Updated Oct 11, 2019

SQL MID Function: Main Tips

  • This function is needed to take out characters from a data record field.
  • There are function equivalents for other database-systems.

Syntax of SQL MID

Example
SELECT MID(col_name,start,length) AS se_name FROM tbl_name;
Parameters Descriptions
col_name Needed. The data record to take out characters.
start Needed. Defines the start position.
length May use. The amount of characters to bring.

 

The SUBSTRING() function in SQL Server:

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

The SUBSTR() function in Oracle:

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

Demo Database

The table called" Customers":

ID Name Name City
1 Ben Choplinks Ben Choplink London
2 Donald Rich Donald Richario Talinn
3 Lilly Smilkins Lilly Smilkin Frankfurt
4 Brandinina Tom Hitchins Dublin
5 Carizmos Christiano Kerrys Paris

SQL MID: Example

In the ode example below picks out the primary four data records from the column "City" in the table "Customers":

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

SQLite Syntax: Example

Example
SELECT SUBSTR(City,1,4) AS ShortCity from Customers;
Learn SQL
Introduction
Syntax
Data Types
Server Data Types
Commands
Commands List
Wildcards
Constraints
Aggregate Functions
Date Functions
Date Format
Injection
SQL Server Hosting
Views
Auto-incrementation
SQL Operators
AS
AND & OR
IN
BETWEEN
WHERE
GROUP BY
HAVING
ORDER BY
LIKE
NOT
NOT EQUAL
UNION
NULL
NOT NULL
DEFAULT
UNIQUE
FOREIGN KEY
PRIMARY KEY
CHECK
Indexes
ALTER TABLE
CREATE DATABASE
CREATE TABLE
DELETE
DROP
INSERT INTO SELECT
INSERT INTO
SELECT
SELECT DISTINCT
SELECT INTO
SELECT TOP
UPDATE
FULL OUTER JOIN
INNER JOIN
JOIN
LEFT JOIN
RIGHT JOIN
AVG()
COUNT
FIRST
LAST
MAX
MIN()
SUM()
LEN
UCASE
MID
NOW
ROUND
FORMAT
LOWER
CONVERT
ISNULL