Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Databases
  • SQL
  • MySQL
  • PostgreSQL
  • PL/SQL
  • MongoDB
  • SQL Cheat Sheet
  • SQL Interview Questions
  • MySQL Interview Questions
  • PL/SQL Interview Questions
  • Learn SQL and Database
Open In App
Next Article:
RTRIM() Function in MySQL
Next article icon

SUBSTRING() function in MySQL

Last Updated : 22 Sep, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report

SUBSTRING() :
function in MySQL is used to derive substring from any given string .It extracts a string with a specified length, starting from a given location in an input string. The purpose of substring is to return a specific portion of the string.

Syntax :

  SUBSTRING(string, start, length)  OR  SUBSTRING(string FROM start FOR length)  

Parameters :
This method accepts three-parameter as mentioned above and described below.

  • string –
    Input String from which to extract.
  • start –
    The starting position. If it is a positive number, this function extracts from the beginning of the string. If it is a negative number, this function extracts from the end of the string.
  • length –
    It is optional. It identifies the number of characters to extract. If it is not given The whole string is returned from the starting position.

Example-1 :
Deriving substring from a given string without giving length parameter.

  SELECT SUBSTRING("GeeksForGeeks", 3) AS Sub_String;  

Output :

Sub_String
eksForGeeks

Example-2 :
Deriving substring from a given string when length parameter is given.

  SELECT SUBSTRING("GeeksForGeeks", 3, 8) AS Sub_String;   

Output :

Sub_String
eksForGe

Example-3 :
Deriving substring from a given string when starting position is -ve, i.e: starting from end.

   SELECT SUBSTRING("GeeksForGeeks", -3 ) AS Sub_String;   

Output :

Sub_String
eks

Example-4 :
Extracting all substring from the text column in a Table.

Table : Student_Details

Student_Id Student_Name
101 Virat
102 Rohit
103 Rahul
104 Sikhar

  SELECT SUBSTRING( Student_Name, 2 ) AS Sub_String FROM Student_Details ;  

Output :

Sub_String
irat
ohit
ahul
ikhar



Next Article
RTRIM() Function in MySQL
author
jana_sayantan
Improve
Article Tags :
  • SQL
  • mysql

Similar Reads

  • SUBSTRING_INDEX() function in MySQL
    SUBSTRING_INDEX() function in MySQL is used to return a substring from a string before a specified number of occurrences of the delimiter. Syntax : SUBSTRING_INDEX( str, delim, count ) Parameter : This method accepts three-parameter as mentioned above and described below : str : The original string
    2 min read
  • TRIM() Function in MySQL
    TRIM() function in MySQL is used to clean up data. It is also used to remove the unwanted leading and trailing characters in a string. Syntax : TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str) Parameter : This method accepts three-parameter as mentioned above and described below : BOTH | LEADIN
    2 min read
  • SUBDATE() function in MySQL
    SUBDATE() function in MySQL is used to subtracts a time value (as interval) from a given date. Syntax : SUBDATE(date, INTERVAL expr unit) Parameter : This function accepts three parameters as given below : date : First specified date. expr : The value of the time/date interval to subtract. unit : Th
    2 min read
  • RTRIM() Function in MySQL
    RTRIM() : It is the function in MySQL that is used to remove trailing spaces from a string. Syntax : RTRIM(str) Parameter : RTRIM() function accepts one parameter as mentioned above and described below. str –The string from which we want to remove trailing spaces. Returns : It returns a string after
    3 min read
  • RIGHT() Function in MySQL
    RIGHT() function in MySQL is used to extract a specified number of characters from the right side of a given string. Second argument is used to decide, how many characters it should return. Syntax : RIGHT( str, len ) Parameter : This function accepts two parameter as mentioned above and described be
    3 min read
  • POSITION() function in MySQL
    POSITION() : This function in MySQL is used for finding the location of a substring in a string. It will return the location of the first occurrence of the substring in the string. If the substring is not present in the string then it will return 0. When searching for the location of a substring in
    2 min read
  • TAN() Function in MySQL
    TAN() function : This function in MySQL is used to return the tangent of a specified number. In any right triangle, the tangent of an angle is the length of the opposite side divided by the length of the adjacent side. Similarly, this can also be defined as tangent of x is the sine of x divided by t
    1 min read
  • SQL Server SUBSTRING() Function
    The SQL Server SUBSTRING function extracts a substring from a string, starting at a specified position and with an optional length. The SUBSTRING function also works in Azure SQL Database, Azure SQL Data Warehouse, and Parallel Data Warehouse. SyntaxThe SQL SUBSTRING function syntax is: SUBSTRING(in
    3 min read
  • STRCMP() Function in MySQL
    STRCMP() function in MySQL is used to compare two strings. If both of the strings are same then it returns 0, if the first argument is smaller than the second according to the defined order it returns -1 and it returns 1 when the second one is smaller the first one. Syntax : STRCMP(Str1, Str2) Param
    3 min read
  • SQRT() Function in MySQL
    The SQRT() function in MySQL calculates the square root of a non-negative number, returning NULL for negative inputs. It is a built-in function that provides high precision and is optimized for performance and making it ideal for mathematical and scientific applications. In the article, we will cove
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences