• Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
logo logo
  • Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
ENEN
  • 简体简体
  • 繁體繁體
Client Area

MySQL Command: RIGHT()

December 20, 2023

MySQL Command: RIGHT()

In the world of databases, MySQL is one of the most popular choices for managing and manipulating data. It offers a wide range of commands and functions that allow users to perform various operations efficiently. One such command is RIGHT(), which is used to extract a specified number of characters from the right side of a string. In this article, we will explore the usage and functionality of the RIGHT() command in MySQL.

Syntax

The syntax for the RIGHT() command is as follows:

RIGHT(string, length)

Here, string is the input string from which we want to extract characters, and length specifies the number of characters to be extracted from the right side of the string.

Example

Let’s consider an example to understand how the RIGHT() command works:

SELECT RIGHT('MySQL Command', 6);

The above query will return the last 6 characters from the string ‘MySQL Command’, which is ‘Command’.

Usage

The RIGHT() command can be useful in various scenarios. Here are a few common use cases:

1. Extracting Last N Characters

One of the primary use cases of the RIGHT() command is to extract the last N characters from a string. For example, if you have a column in your database table that stores phone numbers, and you want to extract the last 4 digits, you can use the RIGHT() command as follows:

SELECT RIGHT(phone_number, 4) FROM customers;

This query will return the last 4 digits of the phone numbers stored in the ‘phone_number’ column of the ‘customers’ table.

2. Formatting Dates

The RIGHT() command can also be used to format dates in a specific way. For instance, if you have a date column in your table that stores dates in the ‘YYYY-MM-DD’ format, and you want to extract only the year from it, you can use the RIGHT() command as follows:

SELECT RIGHT(date_column, 4) FROM table_name;

This query will return the year part from the ‘date_column’ in the ‘table_name’ table.

3. Trimming Leading Characters

In some cases, you may want to remove leading characters from a string. The RIGHT() command can help achieve this by extracting the desired number of characters from the right side of the string. For example, if you have a column that stores file paths, and you want to remove the leading directory path, you can use the RIGHT() command as follows:

SELECT RIGHT(file_path, LENGTH(file_path) - LOCATE('/', REVERSE(file_path))) FROM files;

This query will return the file name by removing the leading directory path from the ‘file_path’ column in the ‘files’ table.

Summary

The RIGHT() command in MySQL is a powerful tool for extracting a specified number of characters from the right side of a string. It can be used to extract last N characters, format dates, and trim leading characters. Understanding the usage and functionality of the RIGHT() command can greatly enhance your data manipulation capabilities in MySQL.

For more information on VPS hosting solutions, visit Server.HK.

Recent Posts

  • VPS Hosting vs Shared Hosting: Why the Upgrade Is Worth It for Asia-Facing Websites
  • Hong Kong VPS vs Google Cloud Asia: Which Delivers Better China Performance in 2026?
  • Why No-ICP-Filing Hong Kong Hosting Is the Smart Choice for Cross-Border E-Commerce
  • Hong Kong VPS vs AWS Hong Kong Region: Cost, Latency, and Control Compared
  • Data Privacy Laws in Hong Kong: What VPS Users Need to Know

Recent Comments

  1. metoprolol generic on Hong Kong VPS vs Japan VPS: Head-to-Head for Asia-Pacific Deployments in 2026
  2. levitra price on Top 5 Use Cases for a Hong Kong Dedicated Server in 2026
  3. finasterid on Hong Kong VPS vs Singapore VPS: Which Is Better for Your Asia Business in 2026?
  4. doxycycline hyclate 100mg on How to Set Up a WordPress Site on a Hong Kong VPS with aaPanel (Step-by-Step 2026)
  5. ciprofloxacin 500 mg tablet on How to Choose the Right Hong Kong VPS Plan: A Buyer’s Guide for 2026

Knowledge Base

Access detailed guides, tutorials, and resources.

Live Chat

Get instant help 24/7 from our support team.

Send Ticket

Our team typically responds within 10 minutes.

logo
Alipay Cc-paypal Cc-stripe Cc-visa Cc-mastercard Bitcoin
Cloud VPS
  • Hong Kong VPS
  • US VPS
Dedicated Servers
  • Hong Kong Servers
  • US Servers
  • Singapore Servers
  • Japan Servers
More
  • Contact Us
  • Blog
  • Legal
© 2026 Server.HK | Hosting Limited, Hong Kong | Company Registration No. 77008912
Telegram
Telegram @ServerHKBot