.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Kaviya Balasubramanian
Sgraph Infotech
Imran Ghani

Home >> Interview Question >> Sql Server >> Post New Question Subscribe to Interview Questions

How to delete duplicate rows from table in sql

Posted By :Ashutosh Jha     Posted Date :July 30, 2014    Points :40   Category :Sql Server 
One can achieve this like below-

SELECT min(rowid) FROM table_name B
WHERE A.key_values = B.key_values);

You can also find related Interview Question to How to delete duplicate rows from table in sql  below: 

How To Delete Description Value for a Column in Table using SQL Command?

We can Delete Description from Column using sp_dropextendedproperty System Store Procedure.
Sample Command to Delete Description from Column in a Table:

EXEC sys.sp_dropextendedproperty @name=N'MS_Description', @value=N'My Description for Column Here' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'MyTableName', @level2type=N'COLUMN',@level2name=N'ColumnName' (More...)

How many ways return rows from one table not in another table?

There are at least 5 ways to return data from one table which is not in another table. Two of these are SQL Server 2005 and greater only




4)OUTER APPLY (2005+)

5)EXCEPT (2005+)


Deleting Duplicates rows from the table?

delete from Employee where(EmpId Not In(Select Max(EmpId) from Employee Group By EmpName
Note: EmpId Should Be identity column means Autogenerated column (More...)

How To retrive Duplicate Records when There is no Primary key in a Table?

select city_name
from areas
group by city_name

having count(*) > 1 (More...)

How to select all duplicate records from a table ?

select field, count(field) from TableName group by field having count(*) > 1

where two (or more) records are considered duplicates if they having a common value for a single field (More...)

How to select records from a table where some column names are duplicate and some are different ?

select * from table as A, table as B where A.field1=B.field1 and A.field2=B.field2 and A.field3<>B.field3 (More...)

Difference Between Delete and Truncate

.Delete table is a logged operation, so the deletion of each row gets logged in the transaction log, which makes it slow.

. Truncate table also deletes all the rows in a table, but it won't log the deletion of each row, instead it logs the de-allocation of the data pages of the table, which makes it faster. Of course, truncate table cannot be rolled back.

. Truncate table is functionally identical to delete statement with no "where clause" both remove all rows in the table. But truncate table is faster and uses fewer system and transaction log resources than delete.

. Truncate table removes all rows from a table, but the table structure and its columns, constraints, indexes etc., remains as it is.

. In truncate table the counter used by an identity column for new rows is reset to the seed for the column.

. If you want to retain the identity counter, use delete statement instead.

. If you want to remove table definition and its data, use the drop table statement.

. You cannot use truncate table on a table referenced by a foreign key constraint; instead, use delete statement without a where clause. Because truncate table is not logged, it cannot activate a trigger.

. Truncate table may not be used on tables participating in an indexed view. (More...)

What are the privileges that can be granted on a table by a user to others?

Insert, update, delete, select, references, index, execute, alter, all (More...)

Quick Links For Interview Questions Categories:
ASP.Net Windows Application   .NET Framework   C#   VB.Net   ADO.Net  
Sql Server   SharePoint   Silverlight   OOPs   JQuery   JavaScript/VBScript
Biztalk Patten/Practices .IIS WCF WPF WWF
Networking Aptitude Others   All      

Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.

Now you can find lots of .NET, C#, Vb.Net, SQL Server,Windows, ASP.Net related Questions and their Answers here at www.dotnetspark.com. Our aim is to help you pass your certification Exams (MCP, MCSD, MCAD etc.,) with flying scores and get good name in your company.

So, Start looking our Interview Question section daily and improve your .NET Skills. You can also help others by posting Interview Questions and their Answers in this section.

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend