Prepare for your Next Interview
|
Welcome to the Geeks Talk forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
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...
|
|||||||
| SQL Server SQL Server is a Database Management System(DBMS) by Microsoft |
![]() |
| LinkBack | Thread Tools | Display Modes |
|
|||
|
Delete duplicate record
How can delete duplicate value from a table
Raghvendra rai |
| The Following 2 Users Say Thank You to raghvendra_rai For This Useful Post: | ||
| Sponsored Links |
|
|||
|
Re: Delete duplicate record
To delete duplicate record we use "distinct clause" select distinct(columname) from tablename.
|
| The Following User Says Thank You to venkat_1984 For This Useful Post: | ||
|
|||
|
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 |
|
|||
|
Re: Delete duplicate record
"distinct" is used to eliminate duplicate records for display purpose only,not to delete records from table.
__________________
-- Brijesh Jain Last edited by jainbrijesh; 05-22-2007 at 08:29 AM. |
| The Following User Says Thank You to jainbrijesh For This Useful Post: | ||
|
|||
|
Quote:
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. |
| The Following User Says Thank You to sanghala For This Useful Post: | ||
|
|||
|
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:) |
|
|||
|
Re: Delete duplicate record
Quote:
Rowid is the best way to eliminate duplicate records in Oracle & in SQL Server, the distinct function can be used.
__________________
*** Innila *** |
|
|||
|
Re: Delete duplicate record
Quote:
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. |
|
|||
|
Re: Delete duplicate record
DELETE FROM tablename WHERE rowid not in(SELECT MIN(rowid)FROM tablename GROUP BY column1,column2 )
|
| The Following User Says Thank You to ms_plz For This Useful Post: | ||
|
|||
|
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. |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Delete duplicate records without using "rowid" | Geek_Guest | SQL | 15 | 01-22-2009 06:49 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 |