Mysql SQL DISTINCT Delete duplicate records

Source: Internet
Author: User
Tags mysql tutorial

Mysql tutorial SQL distinct Delete duplicate records

How to Use the distinct keyword in mysql to filter duplicate values in the result list of a select statement

If you want to delete duplicate data when querying data, you can use the distinct keyword to filter duplicate values. The following describes how to use distinct.

Select distinct column_name from table_name;

Let's take a look at a simple example. We have a car list. Each car has an id, brand, type, and color, but now we just list all the brands:

 

Select brand from car;
The result is: audi bmw lexus

As you can see, the brand is displayed several times. But what we need is to know how many different brands there are in db. To obtain this extended query, as shown below:

Select distinct brand from car;
The result is:
Audi bmw
Lexus


 
If you want to know how many different brands there are, we must use count group by. Let's look at the example below.


Select brand, count (brand) from car group by brand;
And the result is: brand count (brand)
Audi 3
Bmw 2
Lexus 2

 

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.