SQL Remove Duplicate Rows: A How-To Guide

Database Star
Database Star
38.7 هزار بار بازدید - 4 سال پیش - 📝 Get my free SQL
📝 Get my free SQL Cheat Sheets: https://www.databasestar.com/get-sql-...
🎓 Learn and become confident in SQL: https://databasestar.mykajabi.com/sql...

Sometimes you'll be working with a database table and you'll notice some duplicate records in the table.

If it's a small table, you can just use a DELETE statement to delete specific records.

However, if it's a large table, then this may not be possible. Well, it could be possible, but it would take a long time.

Fortunately, you can use the power of SQL to remove duplicate records.

There are several ways you can remove duplicate records in SQL. Some of them work in all database vendors (e.g. Oracle, SQL Server, MySQL, and PostgreSQL), and others only work in some vendors.

But you should be able to use at least one of the methods here in your database.

For each of these methods, you'll be able to run a SELECT query to verify the records to delete first, which helps to ensure your query is correct.

In this video, you'll see an example of a table with duplicate records, and see several methods and sample queries for deleting duplicate data.

Each of the methods automatically works out the duplicate rows, so there's no need for you to specify values in an IN clause or anything.
4 سال پیش در تاریخ 1399/07/28 منتشر شده است.
38,794 بـار بازدید شده
... بیشتر