Finding Duplicates SQL

by Nathan 25. July 2011 07:20

There are various ways to find duplicates in sql server.

 

Here are some example SQL Codes for it.

 

select count(*),description, min(entrytime) as firstbet ,max(entrytime) as lastrecord,
datediff(s,min(entrytime),max(entrytime)) as secondsapart
from mytable with(nolock)
where 1=1
group by description
having count(*) > 2

if more than one record you will need to add more columns to the group by statement

select count(*),firstname,lastname, min(datecreated) as firstbet ,
max(datecreated) as lastrecord,
datediff(s,min(datecreated),max(datecreated)) as secondsapart
from mytable with(nolock)
where 1=1
and datecreated > GETDATE()-130
group by firstname,lastname
having count(*) > 2

 

the next step is to remove duplicates here is how it can be done...

 

 

Tags:

SQL

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.6.1.0
Theme by Mads Kristensen