Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 16
  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2006
    Messaggi
    86

    [Mysql] aggiornare campi a null

    Ciao ragazzi sto cercando di settare il campo "Codice_editore" della tabella "Libri" a NULL per tutte le tuble relative al nome dell'editore : "Addison Wesley" Però mysql non effettua l'aggiornamento passandogli questa query :
    codice:
    UPDATE Libri SET l.codice_editore=NULL  WHERE Codice_editore in ( Select codice_editore from editori WHERE Nome_editore='Addison Wesley');

  2. #2
    Utente di HTML.it
    Registrato dal
    Oct 2006
    Messaggi
    86
    Le due tabelle sono cosi composte :
    codice:
    CREATE TABLE Libri(
    	Codice_libro CHAR(4) PRIMARY KEY,
    	Titolo_libro CHAR(30),
    	Codice_editore CHAR(2) REFERENCES Editori(Codice_editore),
    	Tipo_libro CHAR(3),
    	Prezzo_libro DECIMAL(4,2) DEFAULT 0,
    	Paperback CHAR(1)
    ) TYPE=INNODB;
    
    CREATE TABLE Editori(
    	Codice_editore CHAR(2) PRIMARY KEY,
    	Nome_editore CHAR(20),
    	Citta_editore CHAR(20),
    	Stato_editore CHAR(2)
    ) TYPE=INNODB;

  3. #3
    Utente di HTML.it L'avatar di nicola75ss
    Registrato dal
    Nov 2004
    Messaggi
    12,922
    codice:
    update libri as l,editori as e
    set l.codice_editore = null
    where l.codice_editore = e.codice_editore and e.nome_editore = 'Addison Wesley'
    Il termine type è deprecato. Usa engine.

  4. #4
    Utente di HTML.it
    Registrato dal
    Oct 2006
    Messaggi
    86
    Grazie della risposta ma nemmeno con la query che mi hai suggerito funziona. Non viene modificato nulla !

    codice:
    Query OK, 0 rows affected (0.04 sec)
    Rows matched: 0 Changed: 0 Warnings: 0

  5. #5
    Utente di HTML.it L'avatar di nicola75ss
    Registrato dal
    Nov 2004
    Messaggi
    12,922
    Posta qualche riga di dump delle due tabelle.

  6. #6
    Utente di HTML.it
    Registrato dal
    Oct 2006
    Messaggi
    86
    codice:
    LOCK TABLES `libri` WRITE;
    /*!40000 ALTER TABLE `libri` DISABLE KEYS */;
    INSERT INTO `libri` VALUES ('0180','Shyness','BB','PSY','7.65','Y'),
    ('0189','Kane and Abel','PB','NAR','5.55','Y'),
    ('0200','Stranger','BB','NAR','8.75','Y'),
    ('0378','Dunwich Horror and Others','PB','HOR','19.75','N'),('079X','Smokescreen','PB','MYS','4.55','Y'),
    ('0808','Knockdown','PB','MYS','4.75','Y'),
    ('1351','Cujo','SI','HOR','6.65','Y'),
    ('1382','Marcel Duchamp','PB','ART','11.25','Y'),
    ('138X','Death on the Nile','BB','MYS','3.95','Y'),
    ('2226','Ghost from the Grand Banks','BB','SFI','19.95','N'),
    ('2281','Prints of the 20th Century','PB','ART','13.25','Y'),
    ('2766','Prodigal Daughter','PB','NAR','5.45','Y'),
    ('2908','Hymns to the Night','BB','POE','6.75','Y'),
    ('3350','Higher Creativity','PB','PSY','9.75','Y'),
    ('3743','First Among Equals','PB','NAR','3.95','Y'),
    ('3906','Vortex','BB','SUS','5.45','Y'),
    ('5163','Organ','SI','MUS','16.95','Y'),
    
    /*!40000 ALTER TABLE `libri` ENABLE KEYS */;
    UNLOCK TABLES;
    /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
    
    /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
    /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
    /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
    /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
    /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
    /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
    /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
    
    -- Dump completed on 2011-01-14 16:33:02

  7. #7
    Utente di HTML.it
    Registrato dal
    Oct 2006
    Messaggi
    86
    codice:
    DROP TABLE IF EXISTS `editori`;
    /*!40101 SET @saved_cs_client     = @@character_set_client */;
    /*!40101 SET character_set_client = utf8 */;
    CREATE TABLE `editori` (
      `Codice_editore` char(2) NOT NULL,
      `Nome_editore` char(20) DEFAULT NULL,
      `Citta_editore` char(20) DEFAULT NULL,
      `Stato_editore` char(2) DEFAULT NULL,
      PRIMARY KEY (`Codice_editore`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    /*!40101 SET character_set_client = @saved_cs_client */;
    
    --
    -- Dumping data for table `editori`
    --
    
    LOCK TABLES `editori` WRITE;
    /*!40000 ALTER TABLE `editori` DISABLE KEYS */;
    INSERT INTO `editori` VALUES ('AH','Arkham House Publ.','Sauk City','WI'),('AP','Arcade Publishing','New York','NY'),
    /*!40000 ALTER TABLE `editori` ENABLE KEYS */;
    UNLOCK TABLES;
    /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
    
    /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
    /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
    /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
    /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
    /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
    /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
    /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
    
    -- Dump completed on 2011-01-14 16:37:38

  8. #8
    Utente di HTML.it L'avatar di nicola75ss
    Registrato dal
    Nov 2004
    Messaggi
    12,922
    Il dump della tabella editori contiene solo due record i cui codici nemmeno ci sono nell'altra tabella.

  9. #9
    Utente di HTML.it
    Registrato dal
    Oct 2006
    Messaggi
    86
    Originariamente inviato da nicola75ss
    Il dump della tabella editori contiene solo due record i cui codici nemmeno ci sono nell'altra tabella.
    No avevo tolto volontariamente un pò di cose altrimenti non mi fa caricare la pagina ! il dump
    completo della due tabelle si trova qui :
    DUMP

  10. #10
    Utente di HTML.it
    Registrato dal
    Jan 2011
    Messaggi
    1,469
    non c'è nessun libro "Addison Wesley"

    la query è (ovviamente) corretta

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.