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 / aashish lad
-- Here Temp1 is Temporary Table So it will take All records
-- From Mytable With RowNumbar column
-- We can Delete the Record from
SELECT ROW_NUMBER() OVER(PARTITION BY empid ORDER BY empid)
AS RowNumber, * into #temp1 FROM mytable
DELETE FROM #temp1 WHERE RowNumber> 1
INSERT INTO mytable
SELECT * FROM #temp
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
Can you give me some DBCC command options?(Database consistency check) - DBCC CHECKDB - Ensures that tables in the db and the indexes are correctly linked.and DBCC CHECKALLOC - To check that all pages in a db are correctly allocated. DBCC SQLPERF - It gives report on current usage of transaction log in percentage. DBCC CHECKFILEGROUP - Checks all tables file group for any damage.
Is it possible to have clustered index on separate drive from original table location?
What do you understand by physical_only option in dbcc checkdb?
Explain how to maintain a fill factor in existing indexes?
What does the on delete cascade option do?
What is “begin trans”, “commit tran”, “rollback tran” and “savetran”?
How many triggers you can have on a table?
What is scalar user-defined function?
What are key, name and value columns of an attribute? : sql server analysis services, ssas
what is datawarehouse?
How is foreign key related to primary key?
Name some of the open source software that you can use in alternative to SSR?
How to use copy and concatenate commands in SQL?
what is database replicaion? What are the different types of replication you can set up in sql server? : Sql server database administration
What is a mutating table error and how can you get around it?