0

I have a table which looks like this

ID A B C 
1  1 0 0
1  1 0 0
2  1 1 0
2  1 1 0

How can I remove the duplicated rows in SQL so that I am left with a table that looks like this:

ID A B C 
1  1 0 0
2  1 1 0
Beum
  • 61
  • 5

2 Answers2

1

use row_number()

with cte as
(
select *, row_number() over(partition by id order by id) as rn
from tablename
)

delete from cte where rn<>1
Fahmi
  • 37,315
  • 5
  • 22
  • 31
  • I received an errpr stating row number must have an OVER clause with ORDER BY. how can I alter the code to overcome this error – Beum Apr 09 '19 at 09:31
  • @Beum, it's already have that, what is your sql server version – Fahmi Apr 09 '19 at 11:22
1
select distinct * from <table_name>

This is the simplest way.

BlackSwan
  • 374
  • 2
  • 8