DELETE DUPLICATE VALUE IN THE SAME COLUMN – SQL

Sometime, the table has duplicate value as string, number or etc,… And we want to clean that data. But the data is dynamic so we can not hard code for all case of table.

fruits table

id
name

1
Orange ?

2
Apple ?

3
Orange ?

4
Pineappl…


This content originally appeared on DEV Community and was authored by Ha Tuan Em

Sometime, the table has duplicate value as string, number or etc,... And we want to clean that data. But the data is dynamic so we can not hard code for all case of table.

fruits table

id name
1 Orange ?
2 Apple ?
3 Orange ?
4 Pineapple?

In this case, we got have a simple sql like that:

DELETE
  FROM fruits a
 USING fruits b
 WHERE a.id > b.id
   AND a.name = b.name;

Result after excute query

id name
1 Orange ?
2 Apple ?
4 Pineapple?

If several columns have the same names but the datatypes do not match, the NATURAL JOIN clause can be modified with the USING clause to specify the columns that should be used for an EQUIJOIN.

Find out USING in this article

Enjoy your time ?
Thanks for reading.


Buy me a coffee


This content originally appeared on DEV Community and was authored by Ha Tuan Em


Print Share Comment Cite Upload Translate Updates
APA

Ha Tuan Em | Sciencx (2021-08-31T04:52:31+00:00) DELETE DUPLICATE VALUE IN THE SAME COLUMN – SQL. Retrieved from https://www.scien.cx/2021/08/31/delete-duplicate-value-in-the-same-column-sql/

MLA
" » DELETE DUPLICATE VALUE IN THE SAME COLUMN – SQL." Ha Tuan Em | Sciencx - Tuesday August 31, 2021, https://www.scien.cx/2021/08/31/delete-duplicate-value-in-the-same-column-sql/
HARVARD
Ha Tuan Em | Sciencx Tuesday August 31, 2021 » DELETE DUPLICATE VALUE IN THE SAME COLUMN – SQL., viewed ,<https://www.scien.cx/2021/08/31/delete-duplicate-value-in-the-same-column-sql/>
VANCOUVER
Ha Tuan Em | Sciencx - » DELETE DUPLICATE VALUE IN THE SAME COLUMN – SQL. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/08/31/delete-duplicate-value-in-the-same-column-sql/
CHICAGO
" » DELETE DUPLICATE VALUE IN THE SAME COLUMN – SQL." Ha Tuan Em | Sciencx - Accessed . https://www.scien.cx/2021/08/31/delete-duplicate-value-in-the-same-column-sql/
IEEE
" » DELETE DUPLICATE VALUE IN THE SAME COLUMN – SQL." Ha Tuan Em | Sciencx [Online]. Available: https://www.scien.cx/2021/08/31/delete-duplicate-value-in-the-same-column-sql/. [Accessed: ]
rf:citation
» DELETE DUPLICATE VALUE IN THE SAME COLUMN – SQL | Ha Tuan Em | Sciencx | https://www.scien.cx/2021/08/31/delete-duplicate-value-in-the-same-column-sql/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.