RIGHT( )

This MySQL function returns the final length characters from a string.

Syntax

Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).

RIGHT(string, length)

Explanation

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 multi-byte safe.

Examples

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.