To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here

HOME News MS SQL Oracle DB2 Access MySQL PHP Scripts Books Links DBA Talk


Go Back   Database Journal Forums > Related Sites > SQL Course

SQL Course SQL Course > Ask questions about the lessons on SQL Course 1 and 2. If you have problems > with the interface, please post in the Feedback forum

Reply Post New Thread
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 02-17-2003, 11:58 AM
Najjar Najjar is offline
Registered User
 
Join Date: Feb 2003
Location: Tallahassee, Florida USA
Posts: 43
Angry Deleting Duplicate Records

Hi, Please help
I'm trying to Delete Duplicate Records from my table I have this data

199 Name1 email1 add1
199 Name1 email1 add1
200 Name5 email5 add5
200 Name5 email5 add5
200 Name5 email5 add5
201 Name23 email23 add23

I want to delete the duplicate ones and keep only one of them that is what I want to keep

199 Name1 email1 add1
200 Name5 email5 add5
201 Name23 email23 add23

I'm using MS SQL

My table has more than 3500 Records
If you do not help I'll spend the rest of my life deleting the duplicate ones.

Reply With Quote
  #2  
Old 02-17-2003, 10:48 PM
penjaga_kubur penjaga_kubur is offline
Junior Member
 
Join Date: Feb 2003
Location: malaysia
Posts: 3
can you give me the code!!!

hello can you give me the code!!!
Reply With Quote
  #3  
Old 02-18-2003, 05:07 AM
PinkPanther2003 PinkPanther2003 is offline
Senior Member
 
Join Date: Feb 2003
Posts: 102
DELETING DUPLICATES

So how does the database know which record to keep?

The only way I can suggest is create a temp table using

--Create a deduplicated table
SELECT DISTINCT * INTO #NewTable
FROM OldTable

Go
--Delete the old table
DELETE * FROM OldTable

Go

--Repopulate the old table
INSERT INTO OldTable
SELECT * FROM #NewTable

Go
--Clean Up
DROP TABLE #NewTable

Go

However your referential integrity or other constraints may prevent this method from working so I guarentee nothing.

HTH,

Peter
Go
Reply With Quote
  #4  
Old 02-23-2003, 03:35 PM
Tiamiyu Tiamiyu is offline
Junior Member
 
Join Date: Feb 2003
Location: NA
Posts: 3
What you can do is to create a table that contain the list of the duplicate rows, delete the duplicates and the re-insert them back in. Eg:

1. create table temp as select col1,col2,col3,col4,...coln,count(*) no_of_dups from mytable
where group by col1,col2,col3,col4,...coln
having count(*) > 1;

2. Delete these duplicate rows from your table:

delete from mytable where
col1||col2||col3||...coln in (select col1||col2||col3||...coln from temp);

3. Insert the rows you deleted back to the original table
insert into mytab select
col1,col2,col3,col4,...coln from temp;

4. drop the temp table
Drop table temp;



I hope this works....


Tiamiyu Salau
Reply With Quote
  #5  
Old 03-07-2003, 12:01 PM
Najjar Najjar is offline
Registered User
 
Join Date: Feb 2003
Location: Tallahassee, Florida USA
Posts: 43
Thank you very much it worked from the first time but coz this is the first time i'm using this forum my reply was wrong and I thought that it went through
thank you for your time and sorry for the delay but i thought i replyed

Reply With Quote
Reply Post New Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 09:02 PM.


DatabaseJournal Recent Articles


 » Grouping with SQL Server 2008

 » Conducting Service Broker Conversation Usi...

 » SQL Server Consolidation Initiative Under ...

 » Transaction Log Growth, do you need it?

 » New FileMaker Pro 10 Ships With Sleek New ...

Search Database Journal:
 





Acceptable Use Policy

JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers

Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.