Remove duplicate rows in MySQL

Chetan

I have a table with the following fields:

id (Unique)
url (Unique)
title
company
site_id

Now, I need to remove rows having same title, company and site_id. One way to do it will be using the following SQL along with a script (PHP):

SELECT title, site_id, location, id, count( * ) 
FROM jobs
GROUP BY site_id, company, title, location
HAVING count( * ) >1

After running this query, I can remove duplicates using a server side script.

But, I want to know if this can be done only using SQL query.

Chris Henry

A really easy way to do this is to add a UNIQUE index on the 3 columns. When you write the ALTER statement, include the IGNORE keyword. Like so:

ALTER IGNORE TABLE jobs
ADD UNIQUE INDEX idx_name (site_id, title, company);

This will drop all the duplicate rows. As an added benefit, future INSERTs that are duplicates will error out. As always, you may want to take a backup before running something like this...

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Delete duplicate rows in mysql

分類Dev

Duplicate rows after a MySQL query

分類Dev

Remove duplicate rows from two different lists?

分類Dev

MySQL removing Duplicate Rows with Primary Key

分類Dev

How to delete duplicate rows from mysql

分類Dev

SQL Server - Remove duplicate rows and maintain existing primary key

分類Dev

R - Identify and remove rows of a matrix that have a duplicate in another matrix

分類Dev

Concatenate two dataframes and remove duplicate rows based on column value

分類Dev

Pandas Dataframe: Remove duplicate rows and append data to remaining unique row

分類Dev

LINQ to remove duplicate rows from a datatable based on the value of a specific row

分類Dev

How to remove duplicate rows in SELECT request with 5 fields

分類Dev

How to remove duplicate ID rows. While removing, use the rows that has NULL value in another column

分類Dev

Remove Duplicate Comma-Separated Values From MySQL Column with PHP

分類Dev

How to remove all duplicates from a column in excel using VBA only leaving rows that have no duplicate?

分類Dev

how to remove duplicate records but need to keep their child table rows and tag them to survived row

分類Dev

How to remove duplicate rows with CTE when partitioning by another table's column?

分類Dev

remove duplicate entries in one column and linearize the values in multiple rows to a single row

分類Dev

MySQL: remove rows from table if exist in other table with condition

分類Dev

Cumulative sum for duplicate rows

分類Dev

Get rows with a duplicate value

分類Dev

Remove duplicate in a string - javascript

分類Dev

XSL to remove duplicate records

分類Dev

Remove duplicate images

分類Dev

How to remove duplicate entries

分類Dev

Remove duplicate Source to Destination (eg. for 2 different entries(rows), Delhi to Mumbai and Mumbai to Delhi, output should be one)

分類Dev

VBA Excel Removing duplicate rows

分類Dev

Python pandas: flag duplicate rows

分類Dev

Duplicate rows based on its data

分類Dev

Remove duplicate line in a Google Sheet

Related 関連記事

  1. 1

    Delete duplicate rows in mysql

  2. 2

    Duplicate rows after a MySQL query

  3. 3

    Remove duplicate rows from two different lists?

  4. 4

    MySQL removing Duplicate Rows with Primary Key

  5. 5

    How to delete duplicate rows from mysql

  6. 6

    SQL Server - Remove duplicate rows and maintain existing primary key

  7. 7

    R - Identify and remove rows of a matrix that have a duplicate in another matrix

  8. 8

    Concatenate two dataframes and remove duplicate rows based on column value

  9. 9

    Pandas Dataframe: Remove duplicate rows and append data to remaining unique row

  10. 10

    LINQ to remove duplicate rows from a datatable based on the value of a specific row

  11. 11

    How to remove duplicate rows in SELECT request with 5 fields

  12. 12

    How to remove duplicate ID rows. While removing, use the rows that has NULL value in another column

  13. 13

    Remove Duplicate Comma-Separated Values From MySQL Column with PHP

  14. 14

    How to remove all duplicates from a column in excel using VBA only leaving rows that have no duplicate?

  15. 15

    how to remove duplicate records but need to keep their child table rows and tag them to survived row

  16. 16

    How to remove duplicate rows with CTE when partitioning by another table's column?

  17. 17

    remove duplicate entries in one column and linearize the values in multiple rows to a single row

  18. 18

    MySQL: remove rows from table if exist in other table with condition

  19. 19

    Cumulative sum for duplicate rows

  20. 20

    Get rows with a duplicate value

  21. 21

    Remove duplicate in a string - javascript

  22. 22

    XSL to remove duplicate records

  23. 23

    Remove duplicate images

  24. 24

    How to remove duplicate entries

  25. 25

    Remove duplicate Source to Destination (eg. for 2 different entries(rows), Delhi to Mumbai and Mumbai to Delhi, output should be one)

  26. 26

    VBA Excel Removing duplicate rows

  27. 27

    Python pandas: flag duplicate rows

  28. 28

    Duplicate rows based on its data

  29. 29

    Remove duplicate line in a Google Sheet

ホットタグ

アーカイブ