MYSQL - delete duplicate entries by comparing fields.

Discussion in 'Programming' started by slaydragon, May 1, 2008.

  1. #1
    Hello,

    How do I delete duplicate entries in a MySQL database, by comparing contents in specific fields (i.e. not all fields)?

    What is the correct MySQL query to run?

    For example...

    Table Structure:
    Field 1, Field 2, Field 3, Field 4

    Table Contents:
    1000,4564,1612,6386 ROW 1
    2000,7853,1612,5176 ROW 2 (duplicate) - to delete
    3000,2200,6543,2226 ROW 3
    4000,5479,5247,4717 ROW 4
    5000,5345,1267,4247 ROW 5


    I want to delete duplicate rows that have similar contents in fields 3 only. That is, it doesn't matter if the 1st and 4th column have the same contents. As long as fields 3 have same contents, it is considered a duplicate and should be deleted.
     
    slaydragon, May 1, 2008 IP
  2. hendrawan

    hendrawan Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think you can use distinct for this issue
    SELECT DISTINCT(FIELD_TO_DISCINCT) FROM BLAH_BLAH
     
    hendrawan, May 1, 2008 IP