Geeks Talk

Prepare for your Next Interview




Delete duplicate record

This is a discussion on Delete duplicate record within the SQL Server forums, part of the Databases category; How can delete duplicate value from a table Raghvendra rai...


Go Back   Geeks Talk > Databases > SQL Server

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 04-22-2007
Junior Member
 
Join Date: Apr 2007
Location: Delhi
Posts: 2
Thanks: 0
Thanked 3 Times in 2 Posts
raghvendra_rai is on a distinguished road
Delete duplicate record

How can delete duplicate value from a table

Raghvendra rai
Reply With Quote
The Following 2 Users Say Thank You to raghvendra_rai For This Useful Post:
Sponsored Links
  #2 (permalink)  
Old 05-03-2007
Junior Member
 
Join Date: Feb 2007
Location: Switzerland
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
shwetag is on a distinguished road
Re: Delete duplicate record

DELETE FROM our_table
WHERE rowid not in
(SELECT MIN(rowid)
FROM our_table
GROUP BY column1, column2, column3... ;
Reply With Quote
  #3 (permalink)  
Old 05-03-2007
Junior Member
 
Join Date: Apr 2007
Location: India
Posts: 8
Thanks: 3
Thanked 2 Times in 2 Posts
venkat_1984 is on a distinguished road
Re: Delete duplicate record

To delete duplicate record we use "distinct clause" select distinct(columname) from tablename.
Reply With Quote
The Following User Says Thank You to venkat_1984 For This Useful Post:
  #4 (permalink)  
Old 05-22-2007
Junior Member
 
Join Date: May 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
arvindkumarprajapati is on a distinguished road
Re: Delete duplicate record

--for ex.
--if there is a table... like..

Create table Xyz
(
x varchar(5),
y varchar(5)
);

--and you have inserted following row 3 or 4 times..
insert into xyz values('a','b')
---you can use following stored procedure...
create procedure removeduplicate
as
begin
Create table #Xyz
(
x varchar(5),
y varchar(5)
)
insert into #xyz select distinct * from xyz;
delete from xyz
insert into xyz select * from #xyz;
select * from xyz
end
Reply With Quote
  #5 (permalink)  
Old 05-22-2007
Moderator
 
Join Date: Sep 2006
Location: Delhi (India)
Posts: 866
Thanks: 12
Thanked 81 Times in 65 Posts
jainbrijesh is on a distinguished road
Re: Delete duplicate record

Quote:
Originally Posted by venkat_1984 View Post
To delete duplicate record we use "distinct clause" select distinct(columname) from tablename.
"distinct" is used to eliminate duplicate records for display purpose only,not to delete records from table.
__________________
Brijesh Jain
brijesh.tester@yahoo.co.in
http://softwaretestingexpertise.blogspot.com

Last edited by jainbrijesh : 05-22-2007 at 08:29 AM.
Reply With Quote
The Following User Says Thank You to jainbrijesh For This Useful Post:
  #6 (permalink)  
Old 05-23-2007
I am the DON
 
Join Date: Apr 2006
Location: Just on Earth with all....
Posts: 102
Thanks: 1
Thanked 32 Times in 25 Posts
sanghala is on a distinguished road
Post How to Delete duplicate records from a table ???

Quote:
Originally Posted by raghvendra_rai View Post
How can delete duplicate value from a table

Raghvendra rai
Hi Friend,

In order to delete the Duplicate records from a table ---

DELETE from <tablename> t1
where rowid not in ( select max(rowid)
from <tablename> t2
where t1.col1 = t2.col1
and t1.col2 = t2.col2
and t1.col3 = t2.col3)

Here t1 and t2 are one and the same. Just we are getting the records from the same table by using sub-query.
__________________
Sanghala
www.dwforum.net - A Great resource for Data Warehousing Professionals

If you are satisfied with my reply. Please click “Thanks” button which increases the reputation and can serve you better.
Reply With Quote
The Following User Says Thank You to sanghala For This Useful Post:
  #7 (permalink)  
Old 05-23-2007
Junior Member
 
Join Date: Apr 2007
Location: India
Posts: 8
Thanks: 3
Thanked 2 Times in 2 Posts
venkat_1984 is on a distinguished road
Re: Delete duplicate record

Thanks for sending me this message. Tell me the syntax to create a user defined function.
Reply With Quote
  #8 (permalink)  
Old 05-24-2007
Expert Member
 
Join Date: Dec 2006
Location: Chennai
Posts: 197
Thanks: 2
Thanked 16 Times in 14 Posts
Barbie is on a distinguished road
Re: Delete duplicate record

you shall get the syntax in google.
I feel there is no need to post here for such things.
Reply With Quote
  #9 (permalink)  
Old 05-24-2007
Junior Member
 
Join Date: Jan 2007
Location: Chennai
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
prasathlogu is on a distinguished road
Re: Delete duplicate record

Delete from <table_name> where rowid not in(select min(rowid) from
<table_name> group by <all_primary_key_columns>);
Reply With Quote
  #10 (permalink)  
Old 05-25-2007
Expert Member
 
Join Date: Jun 2006
Location: India
Posts: 411
Thanks: 15
Thanked 33 Times in 25 Posts
jamesravid is on a distinguished road
Re: Delete duplicate record

Do we have rowid function in Sql Server??

I think this is the right thread to ask this question since couple of you guys suggested to remove the duplicate records by using rowid function in sql server.
__________________
Cheers,
:) James:)
Reply With Quote
  #11 (permalink)  
Old 05-25-2007
Expert Member
 
Join Date: Sep 2006
Location: India
Posts: 131
Thanks: 1
Thanked 20 Times in 20 Posts
Innila is on a distinguished road
Re: Delete duplicate record

Quote:
Originally Posted by jamesravid View Post
Do we have rowid function in Sql Server??

I think this is the right thread to ask this question since couple of you guys suggested to remove the duplicate records by using rowid function in sql server.
Rowid function is invalid in SQL Server.
Rowid is the best way to eliminate duplicate records in Oracle & in SQL Server, the distinct function can be used.
__________________
*** Innila ***
Reply With Quote
  #12 (permalink)  
Old 06-05-2007
I am the DON
 
Join Date: Apr 2006
Location: Just on Earth with all....
Posts: 102
Thanks: 1
Thanked 32 Times in 25 Posts
sanghala is on a distinguished road
Re: Delete duplicate record

Quote:
Originally Posted by jamesravid View Post
Do we have rowid function in Sql Server??

I think this is the right thread to ask this question since couple of you guys suggested to remove the duplicate records by using rowid function in sql server.


NO, we are not having rowid function in SQL server.

Therefore the above query will not applicable to delete the Duplicates from a table in SQL server.
__________________
Sanghala
www.dwforum.net - A Great resource for Data Warehousing Professionals

If you are satisfied with my reply. Please click “Thanks” button which increases the reputation and can serve you better.
Reply With Quote
  #13 (permalink)  
Old 07-03-2007
Junior Member
 
Join Date: Jul 2007
Location: india
Posts: 5
Thanks: 0
Thanked 1 Time in 1 Post
ms_plz is on a distinguished road
Re: Delete duplicate record

DELETE FROM tablename WHERE rowid not in(SELECT MIN(rowid)FROM tablename GROUP BY column1,column2 )
Reply With Quote
The Following User Says Thank You to ms_plz For This Useful Post:
  #14 (permalink)  
Old 02-13-2008
Junior Member
 
Join Date: Jun 2007
Location: 879,26th Main,9th 'A' Cross,H.S.R-Layout,Sector-1,Bangalore-560034
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
venugopal.pss is on a distinguished road
Re: Delete duplicate record

Rowid is not there in Sql Server 2000.
Rowid can be used in Oracle only.

Do not get confused.

We can delete the duplicate records by using having clause.
Reply With Quote
  #15 (permalink)  
Old 02-13-2008
Junior Member
 
Join Date: Sep 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
eussusn24 is on a distinguished road
Re: Delete duplicate record

DELETE FROM table_name
WHERE ROWID NOT IN (SELECT max(ROWID)
FROM table _name
GROUP BY duplicate_values_field_name);
Reply With Quote
  #16 (permalink)  
Old 03-20-2008
Junior Member
 
Join Date: Mar 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Madesh is on a distinguished road
Re: Delete duplicate record

Row ID function not in Sqlserver 2000 but sql server 2005 row id function is there
Reply With Quote
Reply

  Geeks Talk > Databases > SQL Server


Thread Tools
Display Modes


Similar Threads

Thread Thread Starter Forum Replies Last Post
Delete duplicate records without using "rowid" Geek_Guest SQL 8 3 Weeks Ago 04:03 AM
difference between delete and truncate bvani MY SQL 18 12-13-2007 06:03 AM
I want load the duplicate records to seperate table Geek_Guest Data Warehousing 4 04-06-2007 03:10 AM
remove duplicate values in a source using Informatica JobHelper Data Warehousing 4 02-03-2007 04:13 AM
Delete history vmshenoy Geeks Lounge 1 01-20-2007 01:05 PM


All times are GMT -4. The time now is 12:34 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0