How to remove duplicates from table using SQL query

后端 未结 7 1571
遇见更好的自我
遇见更好的自我 2020-12-17 04:34

I have a table which is as follows:

emp_name   emp_address  sex  matial_status  
uuuu       eee          m    s
iiii       iii          f    s
uuuu       eee         


        
7条回答
  •  时光说笑
    2020-12-17 05:28

    This is not a query but a delete statement. It will delete/remove duplicate rows from your table

    ;with C as
    (
      select row_number() over(partition by DUPLICATE_VAARS_DECISION 
                               order by NODE_EQ_NO) as rn
      from yourtable
    )
    delete C
    where rn > 1
    

    If you are only interested in querying the table and get the non duplicates as a result you should use this instead.

    ;with C as
    (
      select *,
             row_number() over(partition by DUPLICATE_VAARS_DECISION 
                               order by NODE_EQ_NO) as rn
      from yourtable
    )
    select *
    from C
    where rn = 1
    

提交回复
热议问题