Deleting duplicate value at the same column in table of sql
Ha Tuan Em
Posted on August 31, 2021
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.
💖 💪 🙅 🚩
Ha Tuan Em
Posted on August 31, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
aws Mastering AWS Microservices Architecture for High-Traffic Systems: Interview Preparation
November 29, 2024
authorization How to Set Up Authorization in a Bookstore Management System with Go, HTMX, and Permit.io
November 29, 2024