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

Answer Posted / sunil

CREATE TABLE [dbo].[DupTable](
[Name] [nchar](10) NOT NULL,
[Age] [int] NOT NULL
) ON [PRIMARY]

-- Insert the duplicate data into the table...



Select * from DupTable
go

with Emp AS
(
Select Name,Age, ROW_NUMBER() over (order by Name) as
RowNumber FROM DupTable
)
Delete t1 From Emp as T1, Emp as T2
where T1.Name = T2.Name AND T1.Age= T2.Age and T1.RowNumber
> T2.RowNumber
go

Select * from DupTable
go

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can sql servers link to other servers like oracle?

845


What is replication and database mirroring?

1051


Define candidate key, alternate key, and composite key.

925


What is a View ? Can we insert, Update and delete a view?

996


How to execute a sql statement using odbc_exec()?

1147


What is difference in performance between insert top (n) into table and using top with insert?

1053


Tell me what is difference between view and materialized view?

941


How to implement one-to-one, one-to-many and many-to-many relationships while designing tables?

1032


What is nested transaction?

1105


How to find related tables in sql server?

948


What are the new features introduced in SQL Server 2000? What changed between the previous version of SQL Server and the current version?

2366


what is sql server? : Sql server database administration

994


How to select an exiting database using mssql_select_db()?

992


What do you mean by sql server agent?

998


Can you edit the .rdl code associated with a linked report?

163