how to delete duplicate rows from table

Answer Posted / divya mahendra sikarwar

Execute queries:

CREATE TABLE dbo.Test1 (
[ID] [int] ,
[FirstName] [varchar](25),
[LastName] [varchar](25)
) ON [PRIMARY]

INSERT INTO Test1 VALUES(1, ‘Bob’,'Smith’)
INSERT INTO Test1 VALUES(2, ‘Dave’,'Jones’)
INSERT INTO Test1 VALUES(3, ‘Karen’,'White’)
INSERT INTO Test1 VALUES(1, ‘Bob’,'Smith’)
INSERT INTO Test1 VALUES(4, ‘Bobby’,'Smita’)

select identity(int,1,1) as SlNo,* into #temp from Test1

DELETE
FROM #temp
WHERE SlNo NOT IN
(
SELECT MAX(SlNo)
FROM #temp
GROUP BY ID,FirstName,lastname
)

drop table test1

select * into test1 from #temp

alter table test1 drop column SlNo

select * from test1 order by id

Is This Answer Correct ?    6 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is single-user mode and what are the steps you should follow to start sql server in single-user mode?

551


Does a full backup include transaction log?

479


What is optimization and its types?

533


Is it possible in sql table to have more than one foreign key?

606


What is dbcc updateusage?

534






What is a derived table?

505


what are the different ways to return the rowcount of a table?

570


which table keeps the locking information? : Sql server administration

517


What is filestream?

554


What is named calculation? : sql server analysis services, ssas

527


How you would rewrite the sql query to return the customerid sorted numerically?

571


This question asked during interview, 2) At the end of each month, a new table is created for each bank that contains monthly metrics consolidated at the account level. The table naming convention is bankX_YYYYMM where X represents the numeric designation of the bank and YYYYMM indicates the 4 digit year and 2 digit month. The tables contain the following fields: name data type description account text account number registered boolean indicates whether the account is registered num_trans integer number of transactions made during the time period spend numeric(9,2) total spend during the time period a) Write a SQL query that will display the total number of transactions and total spend for "Bank1" during the 4th quarter of 2009. b) Write a SQL query that will display the total number of transactions and total spend at "Bank1" and "Bank2", broken out by registered vs. non-registered accounts, during January 2010 not sure what is correct answer and how to solve?

2010


What are the different types of indexes?

607


What is the process of normalization?

552


Difference between drill down and drill through report.

542