How to remove duplicate rows from table?



How to remove duplicate rows from table?..

Answer / Sandeep Aswal

To remove duplicate rows from a table, you can use the DISTINCT keyword or the ROW_NUMBER() window function in SQL Server. Here's an example using ROW_NUMBER():n```nWITH cte AS ( n SELECT col1, col2, col3, row_number() OVER (ORDER BY col1, col2, col3) as rn n FROM your_table n)nSELECT * FROM cte WHERE rn = 1;```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More SQL Server Interview Questions

How to delete an attribute from the emp table

4 Answers  


What Is The Difference Between Primary Key & Super Key

3 Answers   Accenture,


How display code or Text of Stored Procedure using Sql query in Sql Server ?

1 Answers   Wipro,


What is set nocount on?

1 Answers  


How to handle error or exception in sql?

1 Answers  


How to set database to be read_only in ms sql server?

1 Answers  


What is an expression in ms sql server?

1 Answers  


Why truncate is ddl?

1 Answers  


What happens on checkpoint?

1 Answers  


What are the types of subscriptions in SQL Server replication?

1 Answers   HCL,


Explain subquery and state its properties?

1 Answers  


How except clause is differs from not in clause?

1 Answers  


Categories