Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Concatenation
Simple text functions
Modifying strings
14. The LEFT() and RIGHT() functions
Summary

Instruction

Fantastic! You can now get a substring (part of a string) from a larger string. But what if you need a substring located at the beginning or end of the string? Of course you may use the combination of the SUBSTRING() and LENGTH() functions but there are two other functions that let you do this easier: LEFT() and RIGHT().

As you might guess, LEFT() takes the substring starting at the leftmost (leading) character, and RIGHT() starts from the final character and works backwards. All you need to specify is the string and how many characters you want to return:

SELECT RIGHT(name, 3)
FROM item;

In this case, RIGHT() returns the last three letters of an item's name.

Exercise

The boss of the marketing agency would like to get the first letter of their first name and the last letter of their last name of all copywriters that have both of those names (i.e., both columns aren't NULL). Name the columns first_letter and last_letter.

Stuck? Here's a hint!

Use LEFT() for first_name and RIGHT() for last_name. Set the length parameter to 1.