Domanda

È possibile eseguire un comando UPDATE su mysql 5.0 con una selezione secondaria.

Il comando che vorrei eseguire è questo:

UPDATE book_details
SET live = 1 
WHERE ISBN13 = '(SELECT ISBN13 FROM book_details_old WHERE live = 1)';

ISBN13 è attualmente memorizzato come stringa.

Questo dovrebbe aggiornare 10k + righe.

Grazie,

William

È stato utile?

Soluzione

Solo un piccolo cambiamento e hai capito:

UPDATE book_details
SET live = 1 
WHERE ISBN13 in (SELECT ISBN13 FROM book_details_old WHERE live = 1);

Altri suggerimenti

UPDATE table1 t1, table2 t2
SET t1.field_to_change = t2.field_with_data
WHERE t1.field1 = t2.field2;
UPDATE book_details AS bd, book_details_old AS old
SET bd.live=1  
WHERE bd.isbn13=old.isbn13  
AND old.live=1;

Per aggiornare una tabella dai dati in un'altra tabella

AGGIORNAMENTO table1, table2 SET table1.field1 = table2.field1 dove table1.id = table2.id

EX. Transazione UPDATE, transazione SET membro.Memberid = member.memberId DOVE transazione.CardId = member.CardId;

Per aggiornare i dati da un'altra tabella

UPDATE  tab t1
SET     t1.company_name = t2.company_name
FROM    tab t2
WHERE   t1.id = t2.id
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top