Is it possible to delete duplicate rows in a table without
using a temporary table ?
Answer Posted / balaji
yes its very much possible.
create table #student
(name varchar(10),age integer)
insert into #student values ('A',12)
go 2
insert into #student values ('B',13)
go 3
insert into #student values ('C',15)
go 4
insert into #student values ('D',14)
go 5
SET ROWCOUNT 1
DELETE #student FROM #student A WHERE (SELECT COUNT(*) FROM
#student B WHERE A.NAME = B.NAME AND A.AGE = B.AGE) > 1
WHILE @@ROWCOUNT > 0
DELETE #student FROM #student A WHERE (SELECT COUNT(*) FROM
#student B WHERE A.NAME = B.NAME AND A.AGE = B.AGE) > 1
SET ROWCOUNT 0
| Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
How do I open port 1433?
Can the query output be sorted by multiple columns in ms sql server?
How to list all login names on the ms sql server?
What are the basic functions for master, msdb, model, tempdb and resource databases? : SQL Server Architecture
Is it true, that there is no difference between a rule and a check constraint?
How to backup SQL Server Reporting Services ?
What does it mean to invest in the index?
do you know what is a deadlock and what is a live lock? How will you go about resolving deadlocks? : Sql server database administration
Is it possible to create trigger on views?
How to replace given values with null using nullif()?
What happens if date-only values are provided as date and time literals?
What structure can you implement for the database to speed up table reads?
What is logshipping and its purpose?
How to convert a numeric expression from one data type to another?
How can we check the sql server version?