Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


How To delete duplicate record from a particular table?

Answers were Sorted based on User's Feedback



How To delete duplicate record from a particular table?..

Answer / kala suresh

--BY USING A TEMP TABLE TO DELETE DUPLICATE ROWS OF A TABLE
WITH OUT A PRIMARY KEY COLUMN OR AN IDENTITY COLUMN

SELECT Name, age, ROW_NUMBER() OVER(ORDER BY age) AS
'RowNumber' into #temp1 FROM RowNumber

delete from #temp1 where rownumber not in(select
max(rownumber) from #temp1 group by name,age)

delete from rownumber

select * from #temp1 into rownumber

drop table #temp1


--BY USING AN IDENTITY COLUMN TO DELETE DUPLICATE ROWS OF A
--TABLE WITH OUT A PRIMARY KEY COLUMN

delete from rownumber where id not in(select min(id) from
rownumber group by name,age)
select * from rownumber

Is This Answer Correct ?    4 Yes 1 No

How To delete duplicate record from a particular table?..

Answer / sybaseexperties

Mr. Parashu, Ur query will delete all dup rec at all. the
solution should be for del dups but keepning single record.
understand?? :)

Is This Answer Correct ?    4 Yes 2 No

How To delete duplicate record from a particular table?..

Answer / srinivasan

WITH CTE AS
(
SELECT * ,ROW_NUMBER() OVER (PARTITION BY ID,NAME
ORDER BY ID DESC) AS RNUM FROM TABLE A
)

DELETE CTE WHERE RNUM >1

IF U HAVE ANY MORE DOUBTS
MAIL ME MCAVASAN@GMAIL.COM

Is This Answer Correct ?    2 Yes 0 No

How To delete duplicate record from a particular table?..

Answer / manoj

DELETE FROM table_name a
WHERE ROWID >(SELECT min(ROWID)
FROM table_name b
WHERE a.col_1=b.col_1 )

Is This Answer Correct ?    6 Yes 6 No

How To delete duplicate record from a particular table?..

Answer / pavan kumar

Mr. Manoj, the system throws error message as "Incrrect
sysntax near 'a'"

Is This Answer Correct ?    3 Yes 3 No

How To delete duplicate record from a particular table?..

Answer / g2

create table Table1(trowid int not null, tname varchar(100))

insert into table1(trowid, tname) values(1, 'G2')
go 100

declare @row int;
set @row= (select count(*) from table1)
set @row=@row-1
set rowcount @row
delete from table1 -- You can put here conditions with all
the columns also
set rowcount 0
go

Is This Answer Correct ?    1 Yes 1 No

How To delete duplicate record from a particular table?..

Answer / arif jameel

ADD a new identity_column (1,1) on <table>
by

alter table <table_name>
add <Identity_column> int identity(1,1)

delete from <table> where <identity_Column> in
(select max(<identity_Column>) from <table>
group by any <table_column_name>)

drop <identity_column>

Is This Answer Correct ?    2 Yes 2 No

How To delete duplicate record from a particular table?..

Answer / jagan mohan varma

employee
----------------------------
eid ename sal
----- --------- ------
1 jagan 2000
2 mohan 3000
3 varma 4000
********************************
attendence
-------------------------------
id eid date
----------- ----------- -----------------------
10 1 2010-06-10 00:00:00.000
11 1 2010-06-10 00:00:00.000
12 2 2010-06-10 00:00:00.000
13 2 2010-06-10 00:00:00.000
14 3 2010-06-10 00:00:00.000
15 3 2010-06-10 00:00:00.000
16 3 2010-06-10 00:00:00.000
*************************************************

Deleting duplicate records from attendence table could be:
**********************************************************

delete from attandence
where id not in (
select max(atd.id)
from employee emp
inner join attandence atd
on atd.eid = emp.eid group by atd.eid)

Is This Answer Correct ?    0 Yes 0 No

How To delete duplicate record from a particular table?..

Answer / sudhagar

Delete from (select * from <TABLE_NAME> where rowid not in
(select min(rowid) from <TABLE_NAME> group by c1,c2...))

Is This Answer Correct ?    3 Yes 4 No

How To delete duplicate record from a particular table?..

Answer / anil sharma

In sqlserver 2000 we must use a unique id per row then we
can delete duplicate rows.

delete from <tablename> where <rowid> not in (select min
(<rowid> from <tablename> group by co1,col2.)


But in sqlserver 2005 there a function RowId.Which is same
as above concept.It return unique id per row.

Is This Answer Correct ?    1 Yes 2 No

Post New Answer

More SQL Server Interview Questions

Please give me the SP for the below scenario. I have two tables named Table1 and Table2...I need to fetch record by record from Table1 and insert the record in to table2 where the value in the sno column of the table1 is even number.

4 Answers   Value Labs,


What is Data model and how to prepare a data model.?

1 Answers   TCS,


What is inline table-value user-defined function?

0 Answers  


what are different types of backups available in sql server? Given a particular scenario, how would you go about choosing a backup plan? : Sql server database administration

0 Answers  


How can sql injection be stopped? : sql server security

0 Answers  


What is user-defined multi-statement table-valued function?

0 Answers  


How to round a numeric value to a specific precision?

0 Answers  


How to Check Whether a Global Temporary Exists in a SQL Database or not?

2 Answers  


What happens if ntwdblib.dll is missing on your machine?

0 Answers  


How do triggers work?

0 Answers  


How many jobs will create for Mirroring, Log Shipping, and Transactional Replication?

4 Answers   IBM,


Write an SQL query if u want to select the data from one block which intern reflects in another block ? thanx,do reply

1 Answers   Covansys,


Categories