Name

RIGHT()

Synopsis

RIGHT(string, length)

This function returns the final length characters from a string. If you want to extract the beginning of the string instead of the end, use the LEFT() function. Both are multibyte-safe. Here is an example:

SELECT RIGHT(soc_sec, 4)
FROM students
WHERE student_id = '43325146122';

This statement retrieves the last four digits of the student’s Social Security number as an identity verification.

Get MySQL in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.