SUBSTRING extracts a part of a string. It's available in both MS SQL Server and MySQL, but MySQL's version provides more functionality. In MySQL you can also use SUBSTR, a synonym for SUBSTRING.
MySQL's SUBSTRING accepts negative values for the start argument — a negative value returns N characters from the right side of the string. MSSQL doesn't support this. Also, in MySQL, omitting the length argument returns the substring from the start position to the end of the string.
Syntax:
SUBSTRING ( expression, start, length )
Where expression is a character, binary, text, ntext, or image expression; start specifies where the returned characters start; and length is a positive integer specifying how many characters to return (a negative length generates an error).
Example — return 4 characters starting from position 3 in 'abcdefgh':
SELECT SUBSTRING('abcdefgh',3,4);
----------------------
cdef

Return the initial character of firstname from the employees table:
SELECT SUBSTRING(firstname,1,1), Lastname from employees;

Syntax:
SUBSTRING(str,pos), SUBSTRING(str FROM pos), SUBSTRING(str,pos,len), SUBSTRING(str FROM pos FOR len)
Where str is the string expression, pos is the start position, and len is the number of characters to return. FROM/FOR are optional keywords.
Example — same result as the MSSQL example above:
mysql> select SUBSTRING('abcdefgh',3,4);
+----------------------------+
| SUBSTRING('abcdefgh',3,4) |
+----------------------------+
| cdef |
+----------------------------+

Pass a negative value for the START argument to return N characters from the right:
mysql> select SUBSTRING('abcdefgh',-4,3);
+-----------------------------+
| SUBSTRING('abcdefgh',-4,3) |
+-----------------------------+
| efg |
+-----------------------------+

You can combine CONCAT with SUBSTRING for formatted output:
mysql> select concat(substr(firstname,1,1),'. ',lastname) as EmpName from employees;
+----------------+
| EmpName |
+----------------+
| N. Davolio |
| A. Smythe |
| J. Leverling |
+----------------+

Omitting the length argument returns the substring from the start position to the end of the string:
mysql> select SUBSTR('abcdefgh',3);
+-----------------------+
| SUBSTR('abcdefgh',3) |
+-----------------------+
| cdefgh |
+-----------------------+

MySQL also provides SUBSTRING_INDEX, which returns words occurring before a given number of delimiter occurrences.
Syntax:
SUBSTRING_INDEX(str, delim, count)
Returns the substring from str before count occurrences of delim. If count is positive, everything to the left of the final delimiter is returned; if negative, everything to the right.
Example — return 2 words from the "." delimiter:
mysql> select SUBSTRING_INDEX('www.dbload.com','.',2);
+-------------------------------------------+
| SUBSTRING_INDEX('www.dbload.com','.',2) |
+-------------------------------------------+
| www.dbload |
+-------------------------------------------+

A negative count returns words from the right:
mysql> select SUBSTRING_INDEX('www.dbload.com','.',-2);
+---------------------------------------------+
| SUBSTRING_INDEX('www.dbload.com','.',-2) |
+---------------------------------------------+
| dbload.com |
+---------------------------------------------+
