Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

sql
mysql
right
communitycreator

What is RIGHT() in SQL?

Harris Amjad

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

The RIGHT() function returns a specific number of characters from the right side of a string.

Figure 1 shows a visual representation of the RIGHT() function.

Figure 1: Visual representation of RIGHT() function

Syntax

RIGHT(string, numOfChars)

Parameters

The RIGHT() function requires two parameters:

  • A string from which the characters need to be extracted.

If a number instead of a string is sent as a parameter, then the number will be cast to a string and then the function will be applied.

  • Number of characters that need to be extracted.

Return value

The RIGHT() function returns the specific number of characters from the right side of a string sent as a parameter.

If the number of characters is greater than the actual length of the string, then the function returns the entire string.

Code

-- string sent
SELECT RIGHT('HELLO',3);
-- number of characters greater than length of string
SELECT RIGHT('HELLO',7);
-- number is sent instead of string
-- it will be cast as a string and then right() is applied
SELECT RIGHT(12345,2);

RELATED TAGS

sql
mysql
right
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring