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...


Write a query to delete duplicate records in SQL SERVER

Answers were Sorted based on User's Feedback



Write a query to delete duplicate records in SQL SERVER..

Answer / saurabh dixit

DECLARE @people TABLE
(
name VARCHAR(32),
age INT
)
insert into @people
select Name,age From People group by Name,Age having COUNT(name)>1

delete People from People pe
join @people p on pe.name=p.name and pe.age=p.age

Is This Answer Correct ?    0 Yes 1 No

Write a query to delete duplicate records in SQL SERVER..

Answer / prakash patel

delete from tbl_test where ID in
(select ID from tbl_test group by ID having count(ID) > 1)

Is This Answer Correct ?    0 Yes 1 No

Write a query to delete duplicate records in SQL SERVER..

Answer / vaishali

set rowcount 1
delete from stud
where (select count(*) from stud a where stud.roll_no =
a.roll_no) > 1
while @@rowcount<>0
delete from stud
where (select count(*) from stud a where stud.roll_no =
a.roll_no) > 1
set rowcount 0

Is This Answer Correct ?    3 Yes 6 No

Write a query to delete duplicate records in SQL SERVER..

Answer / shashank shrivastava

Table-admin
------------------
adminID adminName
1 admin
2 tester
3 admin

SQL:
---------------
DELETE admin.* FROM admin,
(SELECT count(adminName) as c, MAX(adminID) as m from
admin GROUP BY adminName HAVING c>1) as new_admin
WHERE admin.adminID=new_admin.m

Is This Answer Correct ?    1 Yes 5 No

Write a query to delete duplicate records in SQL SERVER..

Answer / senthilsjc

This query delete duplicate records(but not delete both
duplicate)
set rowcount 1
delete yourtable
from yourtable a
where (select count(*) from yourtable b where b.name=a.name
and b.age=a.age)>1
while @@rowcount >0
delete yourtable
from yourtable a
where(select count(*) from yourtable b b.name=a.name and
b.age=a.age)>1
set rowcount 0

Is This Answer Correct ?    6 Yes 12 No

Write a query to delete duplicate records in SQL SERVER..

Answer / subrata paul

Delete TOP(1)from example where[ID]=1

Is This Answer Correct ?    4 Yes 10 No

Write a query to delete duplicate records in SQL SERVER..

Answer / ashish kumar

select * from dbo.duplicatetest
set rowCount 1
delete from dbo.duplicatetest where iD=1;
set rowCount 0

Is This Answer Correct ?    3 Yes 10 No

Write a query to delete duplicate records in SQL SERVER..

Answer / rajkamal

delete form emp
where (select distinct(ename)from emp)

Is This Answer Correct ?    3 Yes 11 No

Write a query to delete duplicate records in SQL SERVER..

Answer / vinod singh kushwah

Delete From Tablename where(ID Not in (Select max(ID) from
Tablename Group by name))

Tablename :Friend

ID Name Age city
101 vinod 22 Gwalior
102 Pritesh 23 Gwalior
102 Pritesh 23 Gwalior
103 Arvind 24 Gwalior


Here Id-102 is repeated so friend if u want to delete this
duplicate raw Try Above code in Sql-sever

Is This Answer Correct ?    4 Yes 13 No

Write a query to delete duplicate records in SQL SERVER..

Answer / anuj

You have Two option You can use keyword Distinct or Group By Both will help you to delete dublicate records

Is This Answer Correct ?    1 Yes 11 No

Post New Answer

More SQL Server Interview Questions

What does man by sql wildcard characters in sql server?

0 Answers  


Give the query of getting last two records from the table in SQL SERVER?

0 Answers   Petranics Solutions,


Which index created when Create Index on table(col), Why

2 Answers   CGI,


What would be the Expected Salary For SQL Server Developer for 3 years exp. as per indian market?

7 Answers  


When we should use @@error?

0 Answers  


What happens to a trigger with multiple affected rows?

0 Answers  


what is hash table

3 Answers   ILFS, Teledata,


find the 3rd max salary

10 Answers  


what is the difference between procedure and function.

4 Answers   Thomson,


whate is advantages of sql server 2000

0 Answers  


What is an expression in ms sql server?

0 Answers  


How to work on DTS?what is the main requirement?

1 Answers   Getit, ivan,


Categories