Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Python Programs
    • Java Programs
    • SQL FAQ’s

MySQL MID Function

by suresh

The MySQL MID function is a synonym of the Substring function. This MID String Function returns or extracts a substring from a given string. Let me show you how to write a String MID in MySQL with an example.

MySQL MID Function Syntax

The basic syntax of the MID string in MySQL is as shown below.

MID(String, Start_Position, Length)

MID(String, Start_Position)

Here, Length = number of characters to extract or return. The MySQL MID function allows you to use negative values for the start Position argument. If you use negative values, then Mid function look from right to left (end to start position).

MySQL MID Function Example 1

The following query shows multiple ways to use this Mid string function. First, We used Mid to start at index position 6. In the second statement, it starts at index position 13.

Within the third statement, we used the length (third argument) as 20. It means, Mid function starts at index position 6 and returns 20 characters from position 6.

SELECT MID('abc is working in xyz Company', 6);

SELECT MID('abc is working in xyz Company', 13);

SELECT MID('abc is working in xyz Company', 6, 20);

OUTPUT

MySQL MID Function 1

MySQL MID Example 2

In this String Function example, we used negative values as the index position argument.

The first statement starts at index position -12. It means MySQL Mid function starts at the 12th index position from the right side (i.e.,r).

SELECT MID('Suresh is working for Tutorial Gateway', -12);

SELECT MID('Suresh is working for Tutorial Gateway', -25);

SELECT MID('Suresh is working for Tutorial Gateway', -30);

OUTPUT

MySQL MID Function 2

Here, we used the Start position as negative values and length argument. The first MySQL statement starts at 12th position from the right side of a string and returns four characters (length = 4).

SELECT MID('Suresh is working for Tutorial Gateway', -12, 4);

SELECT MID('Suresh is working for Tutorial Gateway', -25, 15);

SELECT MID('Suresh is working for Tutorial Gateway', 5, 22);

OUTPUT

MySQL MID Function 3

MySQL String MID Example 3

The MySQL String MID function also allows you to select or extract the required number of characters from the column values.

In this example, We are going to use this MySQL string Mid function with different start positions, and lengths on the Email column. Please refer to MySQL Substring function article.

SELECT FirstName,
LastName,
      DepartmentName,
      Email,
      MID(Email, 3),
      MID(Email, -9),
      MID(Email, 3, 6),
      MID(Email, -10, 5)
FROM `MySQL Tutorial`.employe;

OUTPUT

MySQL MID Function 4

Placed Under: MySQL

  • How to Download MySQL
  • Install MySQL on Windows
  • MySQL Create Database
  • MySQL Delete Database
  • MySQL Create Table
  • MySQL Drop Table
  • MySQL SELECT Statement
  • MySQL ALIAS Column
  • MySQL Distinct
  • MySQL Insert Statement
  • MySQL Delete
  • MySQL Truncate Table
  • MySQL WHERE Clause
  • MySQL Order By
  • MySQL Group By
  • MySQL Having Clause
  • MySQL LIMIT
  • MySQL Arithmetic Operators
  • MySQL COALESCE Function
  • MySQL AND Operator
  • MySQL NOT Operator
  • MySQL OR Operator
  • MySQL XOR Operator
  • MySQL BETWEEN Operator
  • MySQL Not Between Operator
  • MySQL GREATEST Function
  • MYSQL LEAST Function
  • MySQL LIKE Operator
  • MySQL NOT LIKE Operator
  • MySQL IFNULL Operator
  • MySQL NULLIF Operator
  • MySQL INTERVAL Operator
  • MySQL IS Operator
  • MySQL IN Operator
  • MySQL NOT IN Operator
  • MySQL IS NOT NULL
  • MySQL IS NULL
  • MySQL Inner Join
  • MySQL Cross Join
  • MySQL Right Join
  • MySQL Left Join
  • MySQL Aggregate Functions
  • MySQL Date Functions
  • MySQL Date Function
  • MySQL String Functions
  • MySQL Numeric Functions
  • C Tutorial
  • C# Tutorial
  • Java Tutorial
  • JavaScript Tutorial
  • Python Tutorial
  • MySQL Tutorial
  • SQL Server Tutorial
  • R Tutorial
  • Power BI Tutorial
  • Tableau Tutorial
  • SSIS Tutorial
  • SSRS Tutorial
  • Informatica Tutorial
  • Talend Tutorial
  • C Programs
  • C++ Programs
  • Java Programs
  • Python Programs
  • MDX Tutorial
  • SSAS Tutorial
  • QlikView Tutorial

Copyright © 2021 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy