remove repeated data in mysql

-1

I have the following table named cadastro : cod | name | age

With the data:

   COD   NOME     IDADE 
    2  | rafael  | 15
    3  | bruno   | 17
    4  | rafael  | 33
    5  | sabrina | 18
    6  | bruno   | 15
    7  | paulo   | 15
    8  | rafael  | 15

Note that some names repeat, I need to run a command on my mysql to erase all repeated names and keep only 1, which contains the cod .

Example:

I have 3 records with the name rafael .

In this case you would have to keep only the 8 | rafael | 15 .

Is it possible to do this?

    
asked by anonymous 30.07.2018 / 16:53

1 answer

2

You can make a DELETE with INNER JOIN in the same table, however in INNER JOIN you will only bring the registers where cod is less than the first table.

DELETE b FROM cadastro a
INNER JOIN cadastro b ON a.nome = b.nome AND b.cod < a.cod
  

Make a backup of the table before running, I do not have your table here   to take the test.

    
30.07.2018 / 17:04