Remove rows with duplicate value for a column in SQL [closed]












0

















From the above table, I want to remove the rows that have the duplicate CODE column. Out of the duplicate rows, the row with the smallest ID_CHECK should be retained.



Output:












share|improve this question















closed as unclear what you're asking by Gordon Linoff, Shree, ewolden, Suraj Rao, AdrianHHH Nov 19 '18 at 12:22


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • 2





    What is the DBMS you are using?

    – Mayank Porwal
    Nov 19 '18 at 11:43
















0

















From the above table, I want to remove the rows that have the duplicate CODE column. Out of the duplicate rows, the row with the smallest ID_CHECK should be retained.



Output:












share|improve this question















closed as unclear what you're asking by Gordon Linoff, Shree, ewolden, Suraj Rao, AdrianHHH Nov 19 '18 at 12:22


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • 2





    What is the DBMS you are using?

    – Mayank Porwal
    Nov 19 '18 at 11:43














0












0








0










From the above table, I want to remove the rows that have the duplicate CODE column. Out of the duplicate rows, the row with the smallest ID_CHECK should be retained.



Output:












share|improve this question


















From the above table, I want to remove the rows that have the duplicate CODE column. Out of the duplicate rows, the row with the smallest ID_CHECK should be retained.



Output:









sql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 12:06









adiga

9,06462242




9,06462242










asked Nov 19 '18 at 11:30









Trinh PhamTrinh Pham

32




32




closed as unclear what you're asking by Gordon Linoff, Shree, ewolden, Suraj Rao, AdrianHHH Nov 19 '18 at 12:22


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









closed as unclear what you're asking by Gordon Linoff, Shree, ewolden, Suraj Rao, AdrianHHH Nov 19 '18 at 12:22


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 2





    What is the DBMS you are using?

    – Mayank Porwal
    Nov 19 '18 at 11:43














  • 2





    What is the DBMS you are using?

    – Mayank Porwal
    Nov 19 '18 at 11:43








2




2





What is the DBMS you are using?

– Mayank Porwal
Nov 19 '18 at 11:43





What is the DBMS you are using?

– Mayank Porwal
Nov 19 '18 at 11:43












1 Answer
1






active

oldest

votes


















1














If I understand correctly, this should be your SQL query:



Select Names, Code, ID_CHECK
FROM
(
Select Names, Code, ID_CHECK,
ROW_NUMBER() OVER(Partition by Name,Code Order By ID_CHECK) as rnk
FROM table
)tmp
WHERE tmp.rnk=1;


Let me know if this works.






share|improve this answer
























  • Please check what output OP pasted. This is what my query also produces. Also, he wanted to remove duplicates, which does not mean he wants a DELETE command.

    – Mayank Porwal
    Nov 19 '18 at 12:27






  • 1





    Thanks you @MayankPorwal , It is sure , Thank for your help .

    – Trinh Pham
    Nov 20 '18 at 2:25


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














If I understand correctly, this should be your SQL query:



Select Names, Code, ID_CHECK
FROM
(
Select Names, Code, ID_CHECK,
ROW_NUMBER() OVER(Partition by Name,Code Order By ID_CHECK) as rnk
FROM table
)tmp
WHERE tmp.rnk=1;


Let me know if this works.






share|improve this answer
























  • Please check what output OP pasted. This is what my query also produces. Also, he wanted to remove duplicates, which does not mean he wants a DELETE command.

    – Mayank Porwal
    Nov 19 '18 at 12:27






  • 1





    Thanks you @MayankPorwal , It is sure , Thank for your help .

    – Trinh Pham
    Nov 20 '18 at 2:25
















1














If I understand correctly, this should be your SQL query:



Select Names, Code, ID_CHECK
FROM
(
Select Names, Code, ID_CHECK,
ROW_NUMBER() OVER(Partition by Name,Code Order By ID_CHECK) as rnk
FROM table
)tmp
WHERE tmp.rnk=1;


Let me know if this works.






share|improve this answer
























  • Please check what output OP pasted. This is what my query also produces. Also, he wanted to remove duplicates, which does not mean he wants a DELETE command.

    – Mayank Porwal
    Nov 19 '18 at 12:27






  • 1





    Thanks you @MayankPorwal , It is sure , Thank for your help .

    – Trinh Pham
    Nov 20 '18 at 2:25














1












1








1







If I understand correctly, this should be your SQL query:



Select Names, Code, ID_CHECK
FROM
(
Select Names, Code, ID_CHECK,
ROW_NUMBER() OVER(Partition by Name,Code Order By ID_CHECK) as rnk
FROM table
)tmp
WHERE tmp.rnk=1;


Let me know if this works.






share|improve this answer













If I understand correctly, this should be your SQL query:



Select Names, Code, ID_CHECK
FROM
(
Select Names, Code, ID_CHECK,
ROW_NUMBER() OVER(Partition by Name,Code Order By ID_CHECK) as rnk
FROM table
)tmp
WHERE tmp.rnk=1;


Let me know if this works.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 '18 at 11:42









Mayank PorwalMayank Porwal

4,9202724




4,9202724













  • Please check what output OP pasted. This is what my query also produces. Also, he wanted to remove duplicates, which does not mean he wants a DELETE command.

    – Mayank Porwal
    Nov 19 '18 at 12:27






  • 1





    Thanks you @MayankPorwal , It is sure , Thank for your help .

    – Trinh Pham
    Nov 20 '18 at 2:25



















  • Please check what output OP pasted. This is what my query also produces. Also, he wanted to remove duplicates, which does not mean he wants a DELETE command.

    – Mayank Porwal
    Nov 19 '18 at 12:27






  • 1





    Thanks you @MayankPorwal , It is sure , Thank for your help .

    – Trinh Pham
    Nov 20 '18 at 2:25

















Please check what output OP pasted. This is what my query also produces. Also, he wanted to remove duplicates, which does not mean he wants a DELETE command.

– Mayank Porwal
Nov 19 '18 at 12:27





Please check what output OP pasted. This is what my query also produces. Also, he wanted to remove duplicates, which does not mean he wants a DELETE command.

– Mayank Porwal
Nov 19 '18 at 12:27




1




1





Thanks you @MayankPorwal , It is sure , Thank for your help .

– Trinh Pham
Nov 20 '18 at 2:25





Thanks you @MayankPorwal , It is sure , Thank for your help .

– Trinh Pham
Nov 20 '18 at 2:25





這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()