Remove rows with duplicate value for a column in SQL [closed]
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
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.
add a comment |
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
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
add a comment |
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
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
sql
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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.
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
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
2
What is the DBMS you are using?
– Mayank Porwal
Nov 19 '18 at 11:43