Discover delete duplicate rows in sql, include the articles, news, trends, analysis and practical advice about delete duplicate rows in sql on alibabacloud.com
User_student (St_name,class,score)Values (' Zhang Si ', ' a ', ' 65 ')Insert into User_student (St_name,class,score)VALUES (' Five ', ' a ', ' 88 ')Insert into User_student (St_name,class,score)VALUES (' Lie triple ', ' B ', ' 97 ')Insert into User_student (St_name,class,score)VALUES (' John Doe ', ' B ', ' 88 ')Insert into User_student (St_name,class,score)VALUES (' Lee ', ' B ', ' 78 ')Insert into User_student (St_name,class,score)VALUES (' Wang San ', ' C ', ' 86 ')Insert into User_student (
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
In a table, some fields are not primary keys and are not unique, but in the process of use, the field does not apply duplicates, and sometimes it repeats. So, to find the row for a repeating field, use the SQL statement:--That is:--select * from table Where repeating field in (Select repeating field from table Group by repeating field having Count (*) >1)--to a specific example Select * from T_exte RM where Mainkeyindex in (select Mainkeyindex from T_
Method 1 Delete yourtable where [id] not in ( Select MAX ([id]) from yourtable Group by (name + Valu) E) Method 2 Delete a from table a LEFT join ( Select (ID) from table GROUP by Name,value ) b on A.id=b.id Where b.id is null Query and delete duplicate records SQL s
1. Querying duplicate Record single fieldsSELECT * from TBL a where exists (select 1 to tbl B where A.username=b.username GROUP by username have count (*) > 1)2. Number of query repetitionsSelect Clistname,count (clistname) from Clalist GROUP by Clistname have Count (*) >13. Delete duplicate records, leaving ROWID minimum recordsDelete from peoplewhere Peopleid i
SQL Duplicate record query
1, look for redundant records in the table, duplicate records are based on a single field (Peopleid) to judge
SELECT * from people
where Peopleid to (select Peopleid from People GROUP by Peopleid have count (Peopleid) > 1)
Case Two:
SELECT * from TestTable
where Numeber to (select number from people group by nu
Tags: blog http sp c log r AD BSWith such a problem, a SQL statement is used to query the names of students who have more than 80 points per course.Here is the tableAnalysis, query each course is more than 80 students. SELECT DISTINCT name from dbo.student WHERE fenshuStatements less than or equal to 80 select name from Dbo.student WHERE fenshuThis is repeated, and it is worthwhile to use the words in the not-in (no-time) statement to spell the two se
SQL statement for mysql to delete duplicate data and mysql to delete data
Create table tmp as select id FROM get_review_url WHERE (no, title, name, content) IN (SELECT no, title, name, content FROM get_review_url group by no, title, name, content having count (*)> 1) AND id not in (select min (id) FROM get_review_url
There are many ways for SQLServer to search for and delete duplicate records in tables. Below I will list several commonly used SQL statements with good performance. If you need them, please refer to them.
There are many ways for SQL Server to find and delete
into duplicate_all
Select * from # tmp
(2) Use ROW_NUMBERCopy codeThe Code is as follows: with tmpAs(Select *, ROW_NUMBER () OVER (partition by c1, c2, c3 order by (getdate () as numFrom duplicate_allWhere c1 = 1)Delete tmp where num> 1
If multiple tables have completely repeated rows, you can use UNION to join multiple tables to a new table with the same structure, SQ
#tmp
From Duplicate_all
where C1 = 1
Go
Delete Duplicate_all where C1 = 1
Go
INSERT INTO Duplicate_all
SELECT * FROM #tmp
(2) using Row_number
Copy Code code as follows:
With TMP
As
(
Select *,row_number () over (PARTITION by c1,c2,c3 Order by (GETDATE ()) as Num
From Duplicate_all
where C1 = 1
)
Delete tmp where num > 1
If multiple tables have co
# tmp(2) Use ROW_NUMBERCopy codeThe Code is as follows:With tmpAs(Select *, ROW_NUMBER () OVER (partition by c1, c2, c3 order by (getdate () as numFrom duplicate_allWhere c1 = 1)Delete tmp where num> 1
If multiple tables have completely repeated rows, you can use UNION to join multiple tables to a new table with the same structure, SQL Server helps remove
sec) Mysql> Delete Duplicate as a from duplicate as a, -> ( -> SELECT * from duplicate group by name has count (1) >1) as B nb sp;-> where a.name=b.name and a.id > b.id; Query OK, 2 rows Affected (0.00 sec) Mysql> select * FROM du
Mysql-amp; gt; SQL statement to delete duplicate data bitsCN.com
Mysql-> SQL statement: delete duplicate data
A question frequently asked during the interview: an SQL statement is use
following prompt:Server: Msg 3604, Level 16, State 1, line 1The duplicate key has been ignored.It indicates that no duplicate rows appear in the Product information temporary table products_temp. Fourth Axe--import new data into the original tableEmpty the original product information sheet products, import the data from the temporary table products_temp, and
also a very streamlined approach.
Look for duplicates and get rid of the smallest one.
The code is as follows
Copy Code
Delete Users_groups as a from users_groups as a,(Select *,min (ID) from Users_groups GROUP by UID has count (1) > 1) as Bwhere A.uid = B.uid and a.id > b.id;(7 row (s) affected)(0 ms taken)Query result (7 records)ID UID GID1 11 5022 107 5023 100 5034 110 5015 112 5016 104 5029 102 501
3. Now l
There are often repeated records in the database. sometimes I want to query duplicate records and display them, and sometimes I want to delete them. next I will introduce how to delete and query duplicate records.
There are often repeated records in the database. sometimes I want to query
object_id (' tempdb.. #tmp ') is not null
drop table #tmp
Go
SELECT DISTINCT * into #tmp
From Duplicate_all
where C1 = 1
Go
Delete Duplicate_all where C1 = 1
Go
INSERT INTO Duplicate_all
SELECT * FROM #tmp
(2) using Row_number
With TMP
As
(
Select *,row_number () over (PARTITION by c1,c2,c3 Order by (GETDATE ()) as Num
From Duplicate_all
where C1 = 1
)
Delete tmp where num > 1
If multip
Nightmare for Developers--delete duplicate records Presumably every developer has had a similar experience, and when querying or counting the database, the query and statistic results are inaccurate due to duplicate records in the table. The solution to this problem is to delete the
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.