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
What happens if date-only values are provided as date and time literals?
how would you write a sql query to compute a frequency table of a certain attribute involving two joins? What changes would you need to make if you want to order by or group by some attribute? What would you do to account for nulls?
How to view existing indexes on an given table using sys.indexes?
What is an execution plan? How would you view the execution plan?
Explain what are the events recorded in a transaction log?
What is NOT NULL Constraint in sql server 2012?
When cursors are useful?
How are the exceptions handled in sql server programming?
How do you create a data source?
You have a table ‘test’ which is a copy of northwind employee table you have written a trigger to update the field ‘hiredate’ with the current date
Explain having clause?
What is the contrast amongst drop and truncate?
List some advantages and disadvantages of stored procedure?
What is join query?
What is policy management?