Ver Mensaje Individual
  #2 (permalink)  
Antiguo 21/10/2009, 14:11
Avatar de huesos52
huesos52
Colaborador
 
Fecha de Ingreso: febrero-2009
Ubicación: Manizales - Colombia
Mensajes: 5.980
Antigüedad: 15 años, 2 meses
Puntos: 360
Respuesta: Como Eliminar registros repetidos

Con un ejemplo

Código mysql:
Ver original
  1. mysql> create table repetidos1(id integer,nombre text);
  2. Query OK, 0 rows affected (0.01 sec)
  3.  
  4. mysql> insert into repetidos1 values(1,'daniel');
  5. Query OK, 1 row affected (0.00 sec)
  6.  
  7. mysql> insert into repetidos1 values(1,'daniel');
  8. Query OK, 1 row affected (0.00 sec)
  9.  
  10. mysql> insert into repetidos1 values(1,'daniel');
  11. Query OK, 1 row affected (0.00 sec)
  12.  
  13. mysql> insert into repetidos1 values(2,'sara');
  14. Query OK, 1 row affected (0.00 sec)
  15.  
  16. mysql> insert into repetidos1 values(2,'sara');
  17. Query OK, 1 row affected (0.00 sec)
  18.  
  19. mysql> insert into repetidos1 values(2,'sara');
  20. Query OK, 1 row affected (0.00 sec)
  21.  
  22. mysql> insert into repetidos1 values(2,'sara');
  23. Query OK, 1 row affected (0.00 sec)
  24.  
  25. mysql> create temporary table repetidos2(id integer,nombre text);
  26. Query OK, 0 rows affected (0.02 sec)
  27.  
  28. mysql> insert into repetidos2 select distinct id,nombre from repetidos1;
  29. Query OK, 2 rows affected (0.01 sec)
  30. Records: 2  Duplicates: 0  Warnings: 0
  31.  
  32. mysql> select *from repetidos1;
  33. +------+--------+
  34. | id   | nombre |
  35. +------+--------+
  36. |    1 | daniel |
  37. |    1 | daniel |
  38. |    1 | daniel |
  39. |    2 | sara   |
  40. |    2 | sara   |
  41. |    2 | sara   |
  42. |    2 | sara   |
  43. +------+--------+
  44. 7 rows in set (0.00 sec)
  45.  
  46. mysql> delete from repetidos1;
  47. Query OK, 7 rows affected (0.02 sec)
  48.  
  49. mysql> insert into repetidos1 select *from repetidos2;
  50. Query OK, 2 rows affected (0.00 sec)
  51. Records: 2  Duplicates: 0  Warnings: 0
  52.  
  53. mysql> select *from repetidos1;
  54. +------+--------+
  55. | id   | nombre |
  56. +------+--------+
  57. |    1 | daniel |
  58. |    2 | sara   |
  59. +------+--------+
  60. 2 rows in set (0.00 sec)
  61.  
  62. mysql>
__________________
Without data, You are another person with an opinion.
W. Edwads Deming