Solved

Delete duplicates from SQL table based on dupe email addresses

Posted on 2009-07-15
4
297 Views
Last Modified: 2012-05-07
I have an SQL table that has a little more than 1,000 records. When I use 'distinct *' to select distinct records into a new table, and then look at email addresses, there are still duplicate records! Why is this?

Can anyone tell me how to delete rows of table data based on dupe email addresses? if I can kill the dupes by looking at the email addresses this would fix my problem. My email address field is called EmailAddr.....and there's no defined primary key on this table. Thanks...
0
Comment
Question by:jazjef
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 8

Expert Comment

by:vsudip
ID: 24860498
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 24860499
Seems like you have differebbt data in one of the other columns
for example

Col 1   col2
a         b
a        c

if you select DISTINCT * from the above table it still returns 2 records

http://sequelserver.blogspot.com/2008/02/deleting-duplicate-records.html
0
 
LVL 8

Accepted Solution

by:
MartinCMS earned 500 total points
ID: 24860745
Try this query

DELETE FROM yourTable
WHERE EXISTS (SELECT 1
            FROM   yourTable AS yt2
            WHERE  yt2.EmailAddr= yourTable.EmailAddrAND
                     yt2.Record_ID < yourTable.Record_ID)

*** Record_ID - could be the record sequence field in your table
0
 
LVL 4

Author Closing Comment

by:jazjef
ID: 31603975
Thanks MartinCMS... I just added the Record_ID field and your statement worked great!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What is GIS method of Geometry data type? 6 36
VMware PVSCSI SQL Server 2016 AlwaysOn 2 37
SQL - Update field value based on two other fields in same table. 13 43
SQL query 45 41
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question