Categories: MySQL FunctionsPHP

Different ways to use RIGHT() Function in MySQL8.

RIGHT() function fetches a number of characters from a string, starting from right. How many characters will be fetched ? It is determined by second parameter i.e length.

It will return NULL, if any of the argument is NULL.

If length parameter has more than the number of characters in string, then string will be returned.

Note : This function is multibyte safe.

RIGHT() : Syntax

RIGHT ( string, length );

RIGHT() : Parameter

[table caption=”” width=”100%” colwidth=”15%|30%|55%” colalign=”left|left|left”]
Name, Required /Optional, Description
string, Required, it is a valid input string.
length, Required, it specifies the length of characters to be fetched.
[/table]


RIGHT() : Output

[table caption=”” width=”100%” colwidth=”20%|80%” colalign=”left|left”]
Return, Description
String, returns the leftmost length characters from the string.
NULL, if any argument is NULL.
[/table]


RIGHT() : Available from

[table caption=”” width=”100%” colwidth=”25%|75%” colalign=”left|left”]
Version, MySQL 4.0
[/table]


RIGHT() Example 1 :  NULL Arguments

It will return NULL, if any of the argument is NULL. Lets see the below example when length, second argument is NULL.

mysql> SELECT RIGHT('tutorialmines',NULL);
+-----------------------------+
| RIGHT('tutorialmines',NULL) |
+-----------------------------+
| NULL                        |
+-----------------------------+
1 row in set (0.03 sec)

Lets see the below example, when string, first argument is NULL.

mysql> SELECT RIGHT(NULL,5);
+---------------+
| RIGHT(NULL,5) |
+---------------+
| NULL          |
+---------------+
1 row in set (0.05 sec)


RIGHT() Example 2 : Basic Usage

Lets see the below example. I will select 8 characters from the right of string.

mysql> SELECT RIGHT('tutorialmines',8);
+--------------------------+
| RIGHT('tutorialmines',8) |
+--------------------------+
| ialmines                 |
+--------------------------+
1 row in set (0.00 sec)

RIGHT() Example 3 :

If length parameter has more than the number of characters in string.

Lets see the below example. Full string is returned in it.

mysql> SELECT RIGHT('tutorialmines',28);
+---------------------------+
| RIGHT('tutorialmines',28) |
+---------------------------+
| tutorialmines             |
+---------------------------+
1 row in set (0.00 sec))

RIGHT()  Example 4 : Database Query

Lets see the below example of how it works within a database query:

mysql> Select  Name as original, RIGHT(Name,3) as Changed 
FROM tbl_employee LIMIT 5;
+------------+---------+
| original   | Changed |
+------------+---------+
| Jyoti Rani | ani     |
| Polla      | lla     |
| Arnav      | nav     |
| Jeevesh    | esh     |
| Tom        | Tom     |
+------------+---------+
5 rows in set (0.01 sec)

See all MySQL String functions MySQL 8 String Functions.


Related articles : UCASE(), UPPER(), LCASE(), LOWER(), TRIM(), RTRIM(), LEFT().


PHP Related articles : TRIM(), LTRIM(), RTRIM(), STRSTR() ,STRCSPN() , STRCHR(), SUBSTR(), PHP STRING FUNCTIONS().


jyoti rani

Recent Posts

Modern Toys, Magical Moments: Why the Best Toy Shop in Noida Is More Than Just a Store

When it comes to children, there’s one universal truth: the right toy can spark imagination, build skills, and make memories…

6 months ago

Rediscovering Joy: A New Era of Creativity & Comfort in Toy Stores

In today’s digital age, where screens and gadgets dominate our children’s lives, there’s something heartwarming about a well-loved plush toy…

6 months ago

Unboxing Imagination: Discovering the Joy of Play at a Toy Store in Noida

In a world dominated by screens and fast-paced routines, it’s easy to forget the simple magic of a toy in…

6 months ago

Imagination Unboxed: Discover Joy at the Toy Shop in Delhi

In the heart of Delhi’s vibrant streets lies a world where imagination meets innovation — the magical universe of toys.…

6 months ago

Play with Purpose: Discovering the Ultimate Toy Store in Noida

When was the last time a toy truly amazed you—not just as a product, but as a thoughtful tool for…

6 months ago

From Tears to Toys: Exploring Modern Childhood through Delhi’s Favorite Toy Shop

In the digital age, the way we experience childhood has changed, but the essence remains the same—imagination, exploration, and joy.…

6 months ago