Home > Database > Mysql Tutorial > How to filter out duplicate data in sql

How to filter out duplicate data in sql

醉折花枝作酒筹
Release: 2021-05-18 17:56:10
Original
26537 people have browsed it

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)
Copy after login

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)
Copy after login

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
Copy after login

How to filter out duplicate data in sql

Remove duplicate data of the same class

select distinct class from user
Copy after login

How to filter out duplicate data in sql

Remove duplicate data of two fields

select distinct name,class from user
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template