How to retrieve duplicate rows in a table?
How to delete the duplicate entries in a table?
Answer Posted / madhur/amrutha
select ROW_NUMBER() OVER (ORDER BY names ASC) AS ROWID, *
into #temp from emp
select * from #temp where ROWID not in(
select b.ROWID from
(
select ROW_NUMBER() OVER (ORDER BY names ASC) AS ROWID, *
from emp
except
SELECT ROW_NUMBER() OVER (ORDER BY names ASC) AS ROWID, *
FROM
(
select names , sal from emp
union
select distinct names,sal from emp) as a ) as b)
drop table #temp
| Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
How to create a login account in ms sql server to access the database engine using "create login" statements?
How to override dml statements with triggers?
What is rank function?
Can we use max in where clause?
What is a derived table?
How to delete an existing row with delete statements in ms sql server?
How to generate random numbers with the rand() function in ms sql server?
How to view the error log for any specific instance? : sql server database administration
Write a SQL query to make a column as unique?
Difference between Inner vs outer joins?
How do I delete a sql server database?
What are subqueries in sql server?
Why do we need different type of parameter?
What are the acid properties?
How to use old values to define new values in update statements in ms sql server?