Want to know how to eliminate duplicate records in sql? we have a huge selection of how to eliminate duplicate records in sql information on alibabacloud.com
SQL deletes duplicate dataThis article provides a mysql statement for deleting duplicate data, that is, there are more than two duplicate data records in the data table, and the information with the smallest number is deleted.Delete 'borough _ name' as a from fke_borough as,
, COL2 after grouping COL1, COL2 content and the number of records in each group.if: SELECT COL1, COL2, COUNT (DISTINCT COL3) as Expr1From MyTestGROUP by COL1, COL2The result is:COL1 COL2 COUNT1 A 12 A 12 B 13 B 14 C 1If the 7th record is changed to 7 4 c cThe result is:COL1 COL2 COUNT1 A 12 A 12 B 13 B 14 C 2That is, press COL1, COL2 after grouping COL1, the contents of COL2 and the number of records in ea
SQL statement for deleting duplicate dataMethod 1
Assume that the duplicate fields are name and address. You must obtain the unique result set of the two fields.Select identity (int, 1, 1) as autoid, * into # tmp from tablenameSelect min (autoid) as autoid into # tmp2 from # tmp group by name, autoidSelect * from # tmp where autoid in (select autoid from # tmp2)
Business requirementsRecently made a small tool for the company to bring data from one database (data source) into another (target database). The data required to import the target database cannot be duplicated. But the situation is that the data source itself has duplicate data. So you need to clear the data source data first.So we summarize the query and processing of the duplicate data. This is only a da
Often encountered in the development of data on the duplication of records, we have to find ways to filter a number of duplicate records, the following I summed up several methods, hope for everyone useful.
Method One,
Select Identity (int,1,1) as id,* into #temp from tabel
SELECT * from #temp where ID in (
Select Max (ID) from #emp where has count (
in (select max (TID) from query_IP group by SIP, EIP)
That is, the maximum TID value of the same group is obtained by grouping the SIP and EIP. Then, delete the content that is not in the original table (that is, smaller ID content in the duplicate content of the same group.This idea can be used to extend a lot of ways to solve SQL problems. For example, a user login table needs to view the recent login
max (TID) from query_IP group by SIP, EIP) That is, the maximum TID value of the same group is obtained by grouping the SIP and EIP. Then, delete the content that is not in the original table (that is, smaller ID content in the duplicate content of the same group.This idea can be used to extend a lot of ways to solve SQL problems. For example, a user login table needs to view the recent login
In thousands of records, there are some same records, how can you use SQL statements, delete duplicates1, look for redundant records in the table, duplicate records are based on a single field (Peopleid) to determineSELECT * from
SQL Multiple primary key tables, when the inserted data is duplicated, are prompted to violate the primary KEY constraint that cannot be inserted by the error. So, how do I find duplicate values for the inserted data? Workaround: Use Group bySuppose there is a table #a , there are saleid,vendorid,comid,price,saleprice,quantity and other fields. The primary key is: Saleid,vendorid,comid three of them. Assu
This tutorial provides two SQL statement codes for deleting duplicate records. One is to use wherein to query duplicate records and then delete them. The other is to use innerjoin to delete duplicate
Tags: style table design while first SOF code span into blogMethod One: Declare @max integer,@id integer
DeclareCur_rowscursorLocal for SelectMain field,Count(*) fromTable nameGroup byMain field having Count(*)> 1
Opencur_rowsFetchCur_rows into @id,@max
while @ @fetch_status=0
begin
Select @max = @max -1
Set RowCount @max
Delete fromTable namewhereMain field= @id
FetchCur_rows into @id,@max
End
Closecur_rowsSet RowCount 0 Method Two: There are two meanings of
Method One: Take advantage of cursors, but be aware of the main field or identity columnDeclare @max integer,@id integerDeclareCur_rowscursorLocal for SelectMain field,Count(*) fromTable nameGroup byMain field having Count(*)> 1Opencur_rowsFetchCur_rows into @id,@max while @ @fetch_status=0beginSelect @max = @max -1Set RowCount @maxDelete fromTable namewhereMain field= @idFetchCur_rows into @id,@maxEndClosecur_rowsSet RowCount 0Method two: Using Temporal table processingMethod TwoThere are two
This article describes three SQL queries for repeating records and deleting duplicate records , and each uses different methods to illustrate other roles and possibilities, as well as its efficiency.
SELECT *, COUNT (distinct name) from table group by name
Results:
ID Name count (distinct name)1 a 12 B 13 C
A table mark
ID Name pay
1 Sheets 31,000
2 Wang Lei 1200
3 Sheets 35,853
4 Wang 58,574
5 Tall 1259
6 Tall 985
===================
How to query the Name field duplicate values, do not know how to write SQL, the result is that Zhang San appeared several times, Wang Lei appeared several times, Tall appeared several times.
In addition, I do not understand the group by this usage and meaning, who can be
The first method of solution:SELECT DISTINCT P1. Email as email from person P1, person P2 where P1. Email=p2. Email and P1. id>p2.id;The second method of solution:Select email from the person group by email have count (email) >1;There are a series of aggregate functions in sql: Sum, COUNT, Max, AVG, these function scopes on multiple recordsSelect sum (population) from b_table;With the GROUP BY clause, you can have the sum and count functions work for
Tags: style blog http color data ar div htmlThis article describes a method for deleting duplicate records in a data table in a SQL Server database.ProjectThe Users table in the database, containing U_name,u_pwd two fields, where U_name exists duplicates, now to implement the deletion of duplicates!Analysis1, create a temporary table new_users, the table structur
Question: How to delete a record with the same field and leave only one record. For example, the table test contains the ID and name fields. If there are records with the same name, only one record is left, and the remaining records are deleted. The content of the name is not fixed, and the number of identical records is not fixed. Use
1, look for redundant records in the table, duplicate records are based on a single field (Peopleid) to determineSelect * from people where inch (Select from Group by having Count >1)2, delete redundant records in the table, duplicate
Recently, I have been sorting out the database of my website. The database is mysql. Because of the increasing access function, I imported access and reviewed the SQL. There are a lot of data, 0.15 million records, about 1 GB. The two fields a and B of some data are repeated, so that duplicate rows can be considered as duplicated data, as long as any row is retai
SQL optimization solution for querying duplicate data in mysql, mysqlsql
When querying non-case-insensitive data in mysql, subqueries are often used, and the upper function is used in subqueries to convert conditions into uppercase. For example:
Copy codeThe Code is as follows:Select * from staticcatalogue where upper (Source) IN (select upper (Source) FROM staticcatalogue group by upper (Source) having c
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.