Implementation of MySQL non-repeated Query

Source: Internet
Author: User

Non-repeated query in MySQL is an important query method in MySQL. The following describes how to implement non-repeated query in MySQL.

No duplicate query in MySQL is a unique query, that is, the query results that meet the conditions but are different from each other. First, let's look at an example:

 
 
  1. select title from employee_data;  
  2.    
  3. +----------------------------+  
  4. | title                      |  
  5. +----------------------------+  
  6. | CEO                        |  
  7. | Senior Programmer          |  
  8. | Senior Programmer          |  
  9. | Web Designer               |  
  10. | Web Designer               |  
  11. | Programmer                 |  
  12. | Programmer                 |  
  13. | Programmer                 |  
  14. | Programmer                 |  
  15. | Multimedia Programmer      |  
  16. | Multimedia Programmer      |  

...

In the preceding example, We query the title (title) in the employee_data table and note that many of the results are duplicated. If we want to get a non-repeated result, we can use the mysql keyword-DISTINCT.

 
 
  1. select DISTINCT title from employee_data;  
  2.    
  3. +----------------------------+  
  4. | title                      |  
  5. +----------------------------+  
  6. | CEO                        |  
  7. | Customer Service Manager   |  
  8. | Finance Manager            |  
  9. | Marketing Executive        |  
  10. | Multimedia Programmer      |  
  11. | Programmer                 |  
  12. | Senior Marketing Executive |  
  13. | Senior Programmer          |  
  14. | Senior Web Designer        |  
  15. | System Administrator       |  
  16. | Web Designer               |  
  17. +----------------------------+  
  18. 11 rows in set (0.00 sec)  
  19.  

In this way, all the company's job categories can be listed without review. In addition, we can also use DISTINCT and ordber by to sort unique (non-duplicated) results, for example:

 
 
  1. select DISTINCT age from employee_data  
  2. ORDER BY age;  
  3.    
  4. +------+  
  5. | age  |  
  6. +------+  
  7. |   25 |  
  8. |   26 |  
  9. |   27 |  
  10. |   28 |  
  11. |   30 |  
  12. |   31 |  
  13. |   32 |  
  14. |   33 |  
  15. |   34 |  
  16. |   35 |  
  17. |   36 |  
  18. |   43 |  
  19. +------+  
  20. 12 rows in set (0.00 sec)  
  21.  
  22.    
  23.  

Introduction to transcoding in mysql command line cmd Environment

Mysql command line parameters

Two methods to fix mysql tables

How to insert an array into a mysql table in php

MySQL table management commands

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.