Function Reference

MID

PostgreSQL equivalent:

A synonym for SUBSTRING: returns a substring from the given position.

MySQL 8.4
MID(str, pos[, len])
  • [ ]optional part
str
Source string
VARCHAR
pos
Start position, counting from 1; a negative one counts from the end of the string
INT
len
Length of the substring, up to the end of the string by default
INTOptional

Return value

A substring; an empty string if pos is 0 or greater than the string length, or len is less than 1

Examples

Three characters from position five

MySQL 8.4
SELECT MID('sql-academy', 5, 3) AS part;
part
aca

Last name after the space

MySQL 8.4
SELECT member_name,
	MID(member_name, LOCATE(' ', member_name) + 1) AS last_name
FROM FamilyMembers;
member_namelast_name
Headley QuinceyQuincey
Flavia QuinceyQuincey
Andie QuinceyQuincey
Lela QuinceyQuincey
Annie QuinceyQuincey
Ernest ForrestForrest
Constance ForrestForrest
Wednesday AddamsAddams

See also