mysql sql DISTINCT delete duplicate records

Source: Internet
Author: User
Keywords Network programming Mysql tutorial
Tags data delete example guide how many how to how to use list

mysql tutorial sql distinct delete duplicate records

How to use the distinct keyword in mysql to filter the list of duplicate values ​​in a select statement

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

select distinct column_name from table_name;

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

select brand from car;
the result is: audi audi audi bmw bmw lexus lexus

As you can see the brand shows several times. But what we want is to know how many different brands are in db. To get this extended query, look like this

select distinct brand from car;
the result is:
audi bmw
lexus



If you want to know how many different brands, then we must use the count group by to achieve the following example


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.