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

MySQL Substr String

by suresh

The MySQL Substr function is a synonym of a Substring function that returns a substring. The Substr string in MySQL also allows you to place negative values as the Position argument. If you use negative values, then substr start looking from end to start position.

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

SELECT SUBSTR(String, Position) FROM Source

SELECT SUBSTR(String FROM Position) FROM Source

SELECT SUBSTR(String, Position, Length) FROM Source

SELECT SUBSTR(String FROM Position FOR Length) FROM Source

MySQL Substr function Example 1

The following query shows multiple ways to use this Substr function.

SELECT SUBSTR('MySQL Tutorial', 7) AS Substr1;

SELECT SUBSTR('MySQL Tutorial' FROM 9) AS Substr2;

SELECT SUBSTR('MySQL Tutorial', 3, 14) AS Substr3;

SELECT SUBSTR('MySQL Tutorial' FROM 3 FOR 11) AS Substr4;

OUTPUT

MySQL Substr String 1

Substr String Example 2

In this MySQL example, we use the -ve values as the argument position in a substr function.

SELECT SUBSTRING('Tutorial Gateway', -7) AS Substr1;

SELECT SUBSTRING('Tutorial Gateway', -14, 8) AS Substr2;

OUTPUT

MySQL Substr String 2

I suggest you refer to the Substring function article to understand this substr function.

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