September 4, 2013 at 10:37 am
Show how to find duplicates based on another field. This can be the primary key, but perhaps not. Perhaps it's a timestamp of some sort.
Show how to query to check and then construct a delete statement based on the select.
September 4, 2013 at 11:17 am
You mean use another existing field to differentiate between duplicates in the rest of the data?
--------------------------------------
When you encounter a problem, if the solution isn't readily evident go back to the start and check your assumptions.
--------------------------------------
It’s unpleasantly like being drunk.
What’s so unpleasant about being drunk?
You ask a glass of water. -- Douglas Adams
September 4, 2013 at 2:23 pm
Yes, as you could choose a primary key, or if one doesn't exist (or isnt' appropriate) another one. This one is really to teach how someone that doesn't know how to remove a duplicate can do so.
September 7, 2013 at 7:14 am
Does the removing the duplicates job include adding a constraint to make sure the problem doesn't recur?
Tom
September 9, 2013 at 11:04 am
Worth mentioning, but not necessary. That's not always a possibility.
September 9, 2013 at 5:33 pm
L' Eomot Inversé (9/7/2013)
Does the removing the duplicates job include adding a constraint to make sure the problem doesn't recur?
I agree that it probably should at least have an honorable mention... except maybe on staging tables that take in data from 3rd party sources.
--Jeff Moden
Change is inevitable... Change for the better is not.
September 10, 2013 at 8:47 am
Steve,
It is mentioned at
http://www.sqlservercentral.com/Forums/Topic793765-145-1.aspx
It uses CTE with delete. Very neat.
create table t(a varchar(1))
insert into t values('b')
insert into t values('a')
insert into t values('b')
insert into t values('a')
with
dup as
(
select a,row_number() over(partition by a order by a) rn
from t
)
delete from dup where rn>1
In Oracle this would be pretty straight forward via the use of the pseudo rowid column that all tables have.
This references a physical (and thus unique) address of each row.
At this link
http://www.codeproject.com/Articles/159785/Physical-location-of-a-row-in-SQL-Server
there is an interesting discussion of undocumented %%physloc%% and %%lockres%% columns starting with SS2008R2.
January 31, 2014 at 9:27 am
Bump
Looking for a writeup here as an article.
February 16, 2014 at 3:20 pm
Would this be of an interest?
Data de-duplication using 2012 window functions.
Simple cases;
1. A set with no surrogate key defined
2. A set with a surrogate key, related records must be updated
Complex cases;
1. Retaining the first value by any chosen sequence
2. Retaining the first good value by any chosen sequence and pattern
3. Retaining the last value by any chosen sequence
4. Retaining the last good value by any chosen sequence and pattern
5. Retaining the most dense value by any chosen pattern
6. Retaining the least dense value by any chosen pattern
Business rule application (possibly a separate article);
1. Rule controlled matching
2. Rule controlled de-duplication
February 18, 2014 at 8:40 am
These would be good. We'd be looking for 2-3 per article to keep this relatively short.
April 10, 2014 at 12:49 pm
Steve, here is a step by step article I wrote on how to remove duplicates from a table in SQL Server. Still waiting for approval for the previous submitted articles, so posting the original link for my website for now. see if this helps.
http://sqlsaga.com/sql-server/how-to-remove-duplicates-from-a-table-in-sql-server/
[/url]
Good Luck 🙂 .. Visit www.sqlsaga.com for more t-sql code snippets and BI related how to articles.
April 11, 2014 at 8:59 am
Eirikur Eiriksson (2/16/2014)
Would this be of an interest?Data de-duplication using 2012 window functions.
Simple cases;
1. A set with no surrogate key defined
2. A set with a surrogate key, related records must be updated
Complex cases;
1. Retaining the first value by any chosen sequence
2. Retaining the first good value by any chosen sequence and pattern
3. Retaining the last value by any chosen sequence
4. Retaining the last good value by any chosen sequence and pattern
5. Retaining the most dense value by any chosen pattern
6. Retaining the least dense value by any chosen pattern
Business rule application (possibly a separate article);
1. Rule controlled matching
2. Rule controlled de-duplication
I think the simple cases are covered.
It would be good to see an article that deletes the first or last value by some sequence. A separate piece could deal with having a pattern.
I hadn't thought about density, but there's an article in there as well.
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply