I have a table EMP in which the values will be like this

EmpId Ename Sal DeptId
11 Ram 10000 10
11 Ram 10000 10
22 Raj 20000 20
22 Raj 20000 20
33 Anil 15000 30
33 Anil 15000 30

I want to delete only duplicate Rows. After Delete I want
the output like this

EmpId Ename Sal DeptId
11 Ram 10000 10
22 Raj 20000 20
33 Anil 15000 30



Answer Posted / kishor kumar

This can be solved by 2 Ways

One way

Create unique index on this Table with ignore duplicate row

2nd way.

1st transfer the data to a temp table bu using Distinct
clause then truncate the EMP table and then transfor the
data from temp table to EMP Table.

select distinct (column names) in to #temp from EMP

Truncate table EMP

INSERT INTO EMP

SELECT * FROM #temp

Is This Answer Correct ?    9 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain about Joins?

603


What are the types of ssrs?

108


Do you know how to implement service broker?

533


What are drilldown reports?

84


What is an identity column in insert statements?

581






Tell me what is difference between clustered and non clustered index?

556


What is the difference between varchar and nvarchar datatypes?

569


What do you mean by 'normalization'?

603


Benefits of Stored Procedures?

563


What is the advantage of sql server?

534


I have all the primary data files, secondary data files as well as logs. Now, tell me can I still restore the database without having a full backup? : sql server database administration

676


How to retrieve error messages using mssql_get_last_message()?

531


what is the difference between openrowset and openquery?

585


What is query optimizer in sql server?

543


What is ms sql server index?

560