• 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: SUBSTRING()

December 20, 2023

MySQL Command: SUBSTRING()

MySQL is a popular open-source relational database management system that provides various functions to manipulate and extract data. One such function is SUBSTRING(), which allows users to extract a substring from a given string based on specified criteria. In this article, we will explore the usage and syntax of the SUBSTRING() command in MySQL.

Syntax

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

SUBSTRING(string, start, length)

Here, string is the input string from which the substring will be extracted. start is the position within the string where the extraction should begin, and length is the number of characters to be extracted.

Examples

Let’s consider a table named “employees” with a column named “name” that stores the names of employees. We can use the SUBSTRING() command to extract a substring from the names based on specific requirements.

Example 1: Extracting a Substring

To extract a substring from the “name” column starting from the 3rd character and with a length of 5 characters, we can use the following query:

SELECT SUBSTRING(name, 3, 5) FROM employees;

This query will return a result set with the extracted substrings.

Example 2: Extracting a Substring with a Condition

We can also use the SUBSTRING() command with a condition to extract a substring based on specific criteria. For example, let’s extract the first name from the “name” column for employees whose names start with the letter “J”:

SELECT SUBSTRING(name, 1, LOCATE(' ', name) - 1) AS first_name FROM employees WHERE name LIKE 'J%';

In this query, we use the LOCATE() function to find the position of the first space in the name. Then, we subtract 1 from that position to get the length of the substring. The result is aliased as “first_name” for clarity.

Conclusion

The SUBSTRING() command in MySQL is a powerful tool for extracting substrings from strings based on specific criteria. It allows users to manipulate and extract data efficiently. By understanding the syntax and examples provided in this article, you can leverage the SUBSTRING() command to meet your data extraction needs in MySQL.

Summary

In summary, the SUBSTRING() command in MySQL allows users to extract substrings from strings based on specified criteria. It is a useful function for manipulating and extracting data efficiently. To learn more about VPS hosting solutions, visit Server.HK.

Recent Posts

  • 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
  • Hong Kong VPS Security Checklist: 10 Steps to Harden Your Server in 2026

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