Tuesday, May 22, 2012

Removing Duplicates through SQL Query

February 14, 2010 by · 1 Comment 

Suppose we have a table in SQL Server, that has duplicates in it. CREATE TABLE T1 ( ProductName varchar(50) ) INSERT INTO T1 VALUES (‘Computer’), (‘Computer’), (‘Printer’), (‘Printer’), (‘Printer’), (‘Scanner’), (‘Scanner’), (‘Scanner’), (‘Scanner’), (‘Camera’), (‘Flash Drive’), (‘Flash Drive’) now use the following query, that will remove duplicates in the temporary table that we just created: [...]

Delete duplicate rows from table

November 1, 2009 by · 1 Comment 

In the above line we are inserting all the distinct row of the "EmployeeTable" to another table "Emp_Temp_Table" (Emp_Temp_Table will create automatically when you use the above query.) Actuall the above query create clone of EmployeeTable and insert all the distinct row inside the Clone Table (Emp_Temp_Table). drop table EmployeeTable sp_rename ‘Emp_Temp_Table’,EmployeeTable’ Then Delete the [...]