Update :
UPDATE termlisttmp b, tablenew p
SET b.Retour = p.Retour
WHERE b.ligne = p.ligne
UPDATE testA
SET libelle = CONCAT(‘N’, substring(libelle, 2))
WHERE LEFT(libelle,2)=’BN’
Insertion de valeurs d’une table dans une autre :
INSERT INTO termlisttmp
(ligne, Aller, Retour)
SELECT ligne, Aller, Retour FROM toto;
Insert sans doublons :
INSERT INTO testA (code,libelle)
SELECT t1.code, t1.libelle FROM testB t1
WHERE NOT EXISTS(SELECT code
FROM testA t2
WHERE t2.code = t1.code)
Détection des doublons :
Suppression des doublons :
DELETE FROM `testB` WHERE id NOT IN (
SELECT id FROM (SELECT max(id) id FROM testB GROUP BY `code`, `libelle`) AS temp
)
Attention, il doit exister une clef primaire unique index ‘id’. Pour l’ajouter à une table existante :
Créer un champ ‘id’ de type clef primaire puis :
ALTER TABLE `testB` MODIFY `id` INT(4) NOT NULL auto_increment
Votre commentaire