• How to delete Duplicate Value except One in mysql?

    How to delete and Select  Duplicate Value except One in mysql?

    Bronze Member Asked on July 27, 2017 in MYSQL.
    Add Comment
  • 2 Answer(s)
    Best answer
    ////// DELETE QUERY
    
    DELETE FROM oc_nv_invboe
    
    WHERE id NOT IN (SELECT *
    
    FROM (SELECT MIN(n.id)
    
    FROM oc_nv_invboe n
    
    GROUP BY n.order_number) X)
    //////////////////////////////////////////
    
    ////// SELECT QUERY
    
    SELECT * FROM oc_nv_invboe
    
    WHERE id NOT IN (SELECT *
    
    FROM (SELECT MAX(n.id)
    
    FROM oc_nv_invboe n
    
    GROUP BY n.order_number) X)
    
    
    Bronze Member Answered on July 27, 2017.
    Add Comment

    How would I delete all duplicate data from a MySQL Table?

    For example, with the following data:

    SELECT * FROM names;
    
    +----+--------+
    | id | name   |
    +----+--------+
    | 1  | google |
    | 2  | yahoo  |
    | 3  | msn    |
    | 4  | google |
    | 5  | google |
    | 6  | yahoo  |
    +----+--------+
    
    

    I would use SELECT DISTINCT name FROM names; if it were a SELECT query.

    How would I do this with DELETE to only remove duplicates and keep just one record of each?

    Default Answered on March 29, 2018.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.