The SUBSTRING() function returns part of the given string based on the given starting point to a certain length in MySQL.
syntax :
SUBSTRING(string, start,length)
the first argument is string field or string value
start is the starting point of the string from where
length defines how many characters need to return or extract, length is optional
the function SUBSTRING returns part of the string.
how does the SUBSTRING function work in MySQL?
let us get by example how the SUBSTRING function works?
select SUBSTRING("MYSQL", 3,3) so SUBSTRING function return "SQL" from "MYSQL" because it had second argument 3 which is say SUBSTRING method to start to return part of after of 3 characters of the given string.
examples :
select SUBSTRING("MYSQL", 3)
// return is SQL
select SUBSTRING("MYSQL", -4)
// return is YSQL
select SUBSTRING("MYSQL", 0)
// return is NULL OR EMPTY
if you give second argument more than main string length than it returns null or empty by SUBSTRING() function in MySQL.
select SUBSTRING("MYSQL",10)
// return is NULL OR EMPTY
if you don't provide the last argument length then it takes as main string full length.
select SUBSTRING("MYSQL",1,2);// return is MY
select SUBSTRING("MYSQL",1);// return is MYSQL