Because of the design requirements, we need to query non-repeated record values, similar problems, we must have met, so we will immediately GOOGLE it and find that there are many such problems and there are many solutions. Please take a closer look.
1. Search for redundant duplicate records in the Table. duplicate records are determined based on a single field (peopleid ).Select * from peopleWhere peopleid in (select peopleid from people group by peopleid having count (peopleid)> 1)
2. Delete
Use SQL to query duplicate recordsCode
1. Search for redundant duplicate records in the Table. duplicate records are determined based on a single field (peopleid ).Select * from peopleWhere peopleid in (select peopleid from people group by
SQL statement for querying and deleting duplicate records
From: distinct (peopleid) to judgeSelect * from peopleWhere peopleid in (select peopleid from people group by peopleid having count (peopleid)> 1)2. Delete
The SQL statement used to query multiple fields, query multiple tables, and delete duplicate records.
SQL repeat record Query
1. Search for redundant duplicate records in the Table. duplicate records are determined based on a single field (peopleId )
1. Search for redundant duplicate records in the Table. duplicate records are determined based on a single field (peopleid ). Select * from peopleWhere peopleid in (select peopleid from people group by peopleid having count(Peopleid)> 1)
2. Delete
MySQL query statistics for a single SELECT statement is often complex in writing statements. The following describes how to use only one SELECT statement to help you.
Where can I use a single SELECT statement to implement MySQL query statistics?
Delete a duplicate record method:
1. Create a new temporary table
The code is as follows
Copy Code
CREATE TABLE tmp as SELECT * from Youtable Group by name (name is not expected to have duplicate columns)
2.
For example, now there is a person table (table name: peosons)If you want to have the name, ID number, address of these three fields exactly the same records query
Copy Code code as follows:
Select p1.*
From persons p1,persons P2
Using the aggregate function count (*) in MySQL enables this functionality, such as querying the records with the highest number of name occurrences in the data table, by grouping by group by name, counting the number of bars in a group by count,
There is a field "name" in Table A,and the "name" value may be the same between different records,Now you need to query the records in the table, the "name" value duplicates the item;Select Name,count (*) from-A Group by Name has Count (*) > 1If the
To do a functional requirement today, sort out the first 10 and inconsistent data from the table, such as the following values in table A:
The code is as follows
Copy Code
Mysql> select * from A;+----+----------+| ID |
SQL statements remove duplicate records, get duplicate records
--Query a table to effectively remove duplicate records, UserID as a self-growing primary key, Roleid as a repeating field
The code is as follows
Copy Code
One, query a field repeat
Copy Code code as follows:
SELECT *
From User u
where U.user_name in (select U.user_name
From User u
GROUP BY U.user_name has count (*) > 1)
Two, delete the duplicate of a few fields in the
drop table Stu;
Drop sequence Seq_stu;
Create sequence Seq_stu; CREATE TABLE Stu (SID number (5) primary key, Sname varchar2, Ssex varchar2 (2) Default ' man ', Sage Number (3), sdept
Number (2));
Insert into Stu values (Seq_stu.nextval, ' Tom ', '
Suppose you have a table of people (table name: person), if you want to name, ID number, address the three fields exactly the same records to find out, using
1: SELECT p1.*
2: From persons p1,persons p2
3: WHERE
Ways to query and delete duplicate records1, look for redundant records in the table, duplicate records are based on a single field (Peopleid) to determineSELECT * from people where Peopleid in (select Peopleid from People GROUP by Peopleid have
In fact, in the database most often used as a query operationBasic syntaxSELECT [All | DISTINCT | Distinctrow] field list as field alias [from table name WHERE conditional expression GROUP by field name | expression [ASC | DESC],
ID Name Course Name score1 Zhang Three Mathematics 692 John Doe Mathematics 893 Zhang Three Mathematics 69Delete the same student redundancy information except for the automatic numberingThe complete SQL statement is as follows:DELETE from TableName
SQL Duplicate Record Query methodAugust 14, 2008 Thursday 21:01
SQL Duplicate record query1, look for redundant records in the table, duplicate records are based on a single field (Peopleid) to determineSELECT * from Peoplewhere
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.