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


if 3 duplicate records in a table,i want to delete 2 duplicate
records by keeping 1 duplicate and 1 original as it is,how?

Answers were Sorted based on User's Feedback



if 3 duplicate records in a table,i want to delete 2 duplicate records by keeping 1 duplicate and ..

Answer / mohamed zunu

create table sampletbl(id int,name varchar(100))

insert into sampletbl values(1,'aa')
insert into sampletbl values(1,'aa')
insert into sampletbl values(1,'aa')


with cte as(
select ROW_NUMBER() over (partition by id order by id) as r_no,* from sampletbl)
delete from cte where r_no>1
select * from sampletbl

Is This Answer Correct ?    9 Yes 1 No

if 3 duplicate records in a table,i want to delete 2 duplicate records by keeping 1 duplicate and ..

Answer / siva raman

By using Rank function we can delete duplicate records in
tables.

Is This Answer Correct ?    6 Yes 3 No

if 3 duplicate records in a table,i want to delete 2 duplicate records by keeping 1 duplicate and ..

Answer / amol maske

DELETE FROM tablename WHERE ROWID NOT IN(
SELECT MIN(ROWID)FROM tablename GROUP BY columnname);

Is This Answer Correct ?    5 Yes 4 No

if 3 duplicate records in a table,i want to delete 2 duplicate records by keeping 1 duplicate and ..

Answer / dhananjay

The simplest way to eliminate the duplicate records is to
SELECT DISTINCT into a temporary table, truncate the
original table and SELECT the records back into the original
table. That query looks like this:

select distinct *
into #holding
from dup_authors

truncate table dup_authors

insert dup_authors
select *
from #holding

drop table #holding

Is This Answer Correct ?    0 Yes 0 No

if 3 duplicate records in a table,i want to delete 2 duplicate records by keeping 1 duplicate and ..

Answer / arun ashok

STEP 1 : Insert distinct value in the one new table.
STEP 2 : Delete the values from existing table.
STEP 3 : Again insert the values from new table to existing
table.

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More SQL Server Interview Questions

Name few of the dcl commands in sql?

0 Answers  


What are the new features introduced in SQL Server 2000 (or the latest release of SQL Server at the time of your interview)? What changed between the previous version of SQL Server and the current version?

0 Answers  


default databases available in sql server and there uses ?

4 Answers   TCS,


Explain different backup plans?

0 Answers  


what is a correlated sub-query? : Sql server database administration

0 Answers  


what are defaults? : Sql server database administration

0 Answers  


What is the purpose of sql profiler in sql server?

0 Answers  


What is SQL Server?

0 Answers   Atos Origin,


What authentication modes does sql server support?

0 Answers  


In which situation you use Self joins?

1 Answers   CarrizalSoft Technologies, HP, TCS,


what is unique and xaml nonclustered index

0 Answers  


What is dirty page?

0 Answers  


Categories