Delete duplicate rows from a table without primary key by
using a single query
Table Employee
empname salary
A 200
B 300
A 200
C 400
D 500
D 500
Output should be
A 200
B 300
C 400
D 500
Answer Posted / swati tripathi
declare myCursor cursor for
select empid
from employee
group by empid
having count(*) > 1
declare @EmpId int
OPEN myCursor;
FETCH NEXT FROM myCursor INTO @EmpId
WHILE @@FETCH_STATUS = 0
BEGIN
delete top(select count(*)-1 from employee where
empid=@EmpId) from employee where empid=@EmpId
FETCH NEXT FROM myCursor INTO @EmpId
END
close myCursor
deallocate myCursor
Is This Answer Correct ? | 11 Yes | 0 No |
Post New Answer View All Answers
Do you know what is replace and stuff function in sql server?
What is the difference between ddl,dml and dcl commands?
Define right outer join?
What is the difference between createstatement and preparedstatement?
Describe in brief sql server monitoring ways.
What are the tables in sql?
What are a database and a data warehouse?
Is sql server difficult to learn?
What is a domain constraint give an example?
What is a performance monitor?
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.
Explain multiserver query
What is openxml in sql server?
what is package and it uses and how can u call a package
Explain transaction server explicit transaction?