• 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: DISTINCT

December 19, 2023

MySQL Command: DISTINCT

When working with databases, it is common to encounter situations where you need to retrieve unique values from a specific column. This is where the MySQL command DISTINCT comes into play. In this article, we will explore the usage and functionality of the DISTINCT command in MySQL.

Understanding DISTINCT

The DISTINCT command is used to eliminate duplicate rows from the result set of a SELECT statement. It operates on a single column or a combination of columns, ensuring that only unique values are returned.

Let’s consider a scenario where we have a table named “customers” with the following data:

+----+----------+-----+
| ID | Name     | Age |
+----+----------+-----+
| 1  | John     | 25  |
| 2  | Jane     | 30  |
| 3  | John     | 35  |
| 4  | Michael  | 40  |
| 5  | Jane     | 45  |
+----+----------+-----+

If we want to retrieve the unique names from the “Name” column, we can use the DISTINCT command as follows:

SELECT DISTINCT Name FROM customers;

The result of this query would be:

+----------+
| Name     |
+----------+
| John     |
| Jane     |
| Michael  |
+----------+

As you can see, the duplicate names “John” and “Jane” have been eliminated, and only the unique values are returned.

Using DISTINCT with Multiple Columns

The DISTINCT command can also be used with multiple columns to retrieve unique combinations of values. Let’s consider a modified version of the previous table:

+----+----------+-----+
| ID | Name     | Age |
+----+----------+-----+
| 1  | John     | 25  |
| 2  | Jane     | 30  |
| 3  | John     | 35  |
| 4  | Michael  | 40  |
| 5  | Jane     | 45  |
+----+----------+-----+

If we want to retrieve the unique combinations of “Name” and “Age” from the table, we can use the DISTINCT command as follows:

SELECT DISTINCT Name, Age FROM customers;

The result of this query would be:

+----------+-----+
| Name     | Age |
+----------+-----+
| John     | 25  |
| Jane     | 30  |
| John     | 35  |
| Michael  | 40  |
| Jane     | 45  |
+----------+-----+

As you can see, the DISTINCT command considers both the “Name” and “Age” columns to determine uniqueness. In this case, the combinations of “John, 25” and “Jane, 30” are considered unique, even though the individual values may appear multiple times.

Conclusion

The DISTINCT command in MySQL is a powerful tool for retrieving unique values from a specific column or combination of columns. It eliminates duplicate rows from the result set, providing valuable insights into the data. Whether you need to retrieve unique names, unique combinations of values, or any other unique data, the DISTINCT command is a handy tool to have in your SQL arsenal.

Summary

In summary, the DISTINCT command in MySQL is used to retrieve unique values from a specific column or combination of columns. It eliminates duplicate rows from the result set of a SELECT statement. Whether you need to retrieve unique names, unique combinations of values, or any other unique data, the DISTINCT command is a powerful tool to have in your SQL toolkit. To learn more about 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. linezolid cost oral on Top 5 Use Cases for a Hong Kong Dedicated Server in 2026
  2. metoprolol generic on Hong Kong VPS vs Japan VPS: Head-to-Head for Asia-Pacific Deployments in 2026
  3. levitra price on Top 5 Use Cases for a Hong Kong Dedicated Server in 2026
  4. finasterid on Hong Kong VPS vs Singapore VPS: Which Is Better for Your Asia Business in 2026?
  5. doxycycline hyclate 100mg on How to Set Up a WordPress Site on a Hong Kong VPS with aaPanel (Step-by-Step 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