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
A few days ago, I read the article in the SQL section of SCID and explained how to quickly delete duplicate records in SQL Server. I browsed it. The author used four methods: creating temporary tables, using cursors, and using unique indexes. After a while, I found that the method I used was the easiest. Good stuff can
Delete duplicate records and save TABLE_NAME Records in #table_name
SELECT DISTINCT * INTO #table_name table_name
Delete from table_name
SELECT * INTO table_name from #table_name
drop table #table_name
Related to this is the "SELECT INTO" option, which can be used in database properties
dialog box, either hook up this item, or execute in Query Analyzer
Execute
Tags: where ideas group art over SEL repeat minimum order byThe first few days of work, there is a small need to delete a table table_a duplicate records (keep one), assuming that the field col_pk repetition to determine the record duplication, then there are several ways: In Oracle, you can use ROWID to delete, which is a very efficient way of writing: DELETE from Table_a WHERE ROWID isn't in (SELECT MIN (
MySQL Tutorial SQL distinct delete duplicate records
How to use the DISTINCT keyword in MySQL to filter duplicate values in the result list of a SELECT statement
If you want to delete duplicate data while querying the data, you can use the DISTINCT keyword to filter the
The following is a general t-SQL template for this operation:
/* Delete from a from -- delete Table A (a is the referenced table to be deleted)(Select row_number () over -- row_number () over is an auto-incrementing column generated from the beginning.(Partition by repeat column 1, repeat column 2, repeat column 3 --, repeat column N partition by is similar to group by but not an aggregate function is used to display all
How can I delete duplicate data when there are duplicate records in the database table?
Of course, the premise is the repeated definition: In the database table, we think that one or more fields are the same, then we think this record is repeated.
See the following table:
Rowid
Dep_id
Dep_name
Company
Aaarj4aaeaaabegaaa
13
Person
After learning about SQL for a while, I found a lot of duplicate records in the table I built to test (not indexed). Later, we summarize some ways to delete duplicate records, in Oracle, you can delete duplicate
. Customer number, A. Company name from customer as a, customer as B
WHERE A. Customer number >= B. Customer number GROUP by a. Customer number, B. Company name order by serial number;
2. SQL Server 2005 construct ordinal column
Method One:
SELECT RANK (DESC) as serial number, customer number, company name from customer;
Method Two:
With TABLE as
(SELECT row_number () over (DESC) as ordinal number, customer number, company name from customer)
SELE
In the system to a customer on-line found that there is a table of duplicate data, the results by troubleshooting code to find that there is a problem with the business logic, after modifying the code needs to be in the database of data deduplication on CSDN to find a solution,do not delete the database on the wire as much as possible, and you should back up the database regardless of any action on the database on the line
--删除重复的记录
delete fr
Test data preparationGive Test_user access to the Scott User EMP table Grant Select on to Test_user;Use Test_user to create an EMP table based on the Scott User's EMP table Create Table as Select * from Scott.emp;Insert the same data again Insert into Select * from EMP;Querying Current data Select * from Order by ASC;You can see that each record appears twice.Delete duplicate records1, delete redundant rec
During this time, the project needs to import the original data to the new database, and the duplicate data needs to be deleted. I use the cursor method to solve this problem. The SQL statement is as follows to avoid forgetting.
Code
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->
--
Delete duplicate data
SQL statements for querying and deleting duplicate records
ASayThere 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 (*) fr
Tags: SQL multi-condition sieve weightUsually we check the weight, and filter the duplicates according to a certain condition.SELECT * FROM dbo. T_ecert Awhere (A.ecertid) in (select Ecertid from T_ecert GROUP by Ecertid+idcard have count (*) > 1)But what if you need to have multiple conditions?Oracle can do thisSELECT * FROM dbo. T_ecert Awhere (A.ecertid,a.idcard) in (select A.ecertid,a.idcard from T_ecert GROUP by Ecertid,idcard have count (*) > 1)
: I built a table in MS SQL, but for a variety of reasons some records are duplicated
: The record is exactly the same.
: Now I want to delete the duplicates, just keep the first one in the duplicate record.
: I seem to have seen a presentation of Oracle in the database,
SELECT DISTINCT * INTO #table_name table_name
Delete from table_name
SELECT * INTO table_name
Repeat: I built a table in MS SQL, but for a variety of reasons some records are duplicated
: The record is exactly the same.
: Now I want to delete the duplicates, just keep the first one in the duplicate record.
: I seem to have seen a presentation of Oracle in the database,
SELECT DISTINCT * INTO #table_name table_name
Delete from table_name
SELECT * INTO
Let's now look at how to delete these records in SQL SERVER 2008, first of all, to simulate making some simple duplicate records:
Copy Code code as follows:
Create Table dbo. Employee (
[Id] int Primary KEY,
[Name] varchar (50),
[Age] int,
[Sex] Bit default 1
)
Insert into Employee ([Id], [Name], [ag
Tags: class delete highlight top update duplicate record color Xiaomi dateInsert duplicates when inserting data accidentally todayThere are no primary key foreign keys in this table, you may insert or delete them arbitrarily.There's a lot of complicated statements on the web that don't solve the problem.Finally, use delete top (1) to solve the problemDelete Top (1from where='xiaomin'can also be usedUpdate Top (1) from the person where name = ' xxxx '
Let's take a look at how you can use it to delete duplicate records in a table:
Copy Code code as follows:
If Exists (Select * FROM Tempdb.Information_Schema.Tables Where table_name like ' #Temp% ')
Drop Table #temp
Create Table #temp ([Id] int, [Name] varchar, [age] int, [SEX] bit default 1)
Go
Insert into #temp ([Id], [Name], [age], [Sex]) Values (1, ' James ', 25,default)
Insert into #t
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 table
Example: There are six records in the table. Where John and Harry records are duplicated.TableA
Copy Co
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.