SQL Server Interview Questions and Answers
<< Previous Question Next Question >>
 Question: 1109 Page Views: 

How can we delete the duplicate rows from a table?



Posted By: Avi Date: 19 September 2009 04:58:46 AM
 Answer:

Lets consider if we have a table Employee with rowid, name and email columns. Then we can use following SQL statement to delete the dublicate rows from Employee table:

DELETE FROM Employee WHERE rowid NOT IN (SELECT MAX(rowid) FROM Employee GROUP BY name, email HAVING COUNT(*)>0)


Posted By: eTechPlanet


Date: 19 September 2009 04:58:46 AM
Post a better Answer if you have
 
(Will show your Gravatar icon)  
  Country flag

Loading
Enter the text as shown in the image FRz9h1
Related Questions
SQL Server : Which conditions are to be kept in mind while using the FOR BROWSE Option in SELECT statement?

Which conditions are to be kept in mind while using the FOR BROWSE Option in SELECT statement?

Following are the conditions:- 1. The table should have time-stamped column with timestamp as datat....
Category: SQL Server Date: 10/1/2010 11:29:07 AM
SQL Server : What is the purpose of FOR BROWSE option in the SELECT statement?

What is the purpose of FOR BROWSE option in the SELECT statement?

FOR BROWSE option which is used at the end of the SELECT statement allows the user to perform the up....
Category: SQL Server Date: 10/1/2010 11:28:07 AM
SQL Server : Which SQL statement doesn't support HOLDLOCK?

Which SQL statement doesn't support HOLDLOCK?

HOLDLOCK cannot be used with the SELECT statement which is having FOR BROWSE option.
Category: SQL Server Date: 10/1/2010 11:27:07 AM
SQL Server : What is HOLDLOCK in SQL?

What is HOLDLOCK in SQL?

HOLDLOCK option directs the SQL server to hold shared lock untill and unless the transaction is comp....
Category: SQL Server Date: 10/1/2010 11:26:07 AM
SQL Server : Discuss how Exclusive Locks are not compatible with other locks.

Discuss how Exclusive Locks are not compatible with other locks.

Exclusive Locks are not compatible with other lock types such as Shared Locks and Update Locks. Exam....
Category: SQL Server Date: 10/1/2010 11:25:07 AM