Home  >  Article  >  Database  >  How to filter out duplicate data in sql

How to filter out duplicate data in sql

醉折花枝作酒筹
醉折花枝作酒筹Original
2021-04-14 17:17:5526476browse

SQL method to filter out duplicate data: Use the "select * from table name where condition" statement to filter out duplicate data; you can use one or more tables, use commas (,) to separate the tables, and use WHERE statement to set query conditions.

How to filter out duplicate data in sql

The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.

Open the database on your computer, and create a new user table with duplicate data as an example.

How to filter out duplicate data in sql

Query the duplicate data of the user table in the database.

select * from user where name in (select name from user group by name having count(name) > 1)

How to filter out duplicate data in sql

Delete duplicate name data

delete from user where   name in (select name from user group by name  having count(name) > 1)

How to filter out duplicate data in sql

Remove duplicate data, here the duplicate data of Zhang San is removed

select distinct name from user

How to filter out duplicate data in sql

Remove duplicate data of the same class

select distinct class from user

How to filter out duplicate data in sql

Remove duplicate data of two fields

select distinct name,class from user

How to filter out duplicate data in sql

Related free learning recommendations: mysql video tutorial

The above is the detailed content of How to filter out duplicate data in sql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn