使用另一个表的数据更新mysql表

时间:2022-09-07 17:04:49

Is it possible to run an UPDATE command on mysql 5.0 with a sub select.

是否可以使用子select在mysql 5.0上运行更新命令。

The command I would like to run is this:

我想运行的命令是:

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

ISBN13 is currently stored as a string.

ISBN13目前存储为一个字符串。

This should be updating 10k+ rows.

它应该更新10k+行。

Thanks,

谢谢,

William

威廉

5 个解决方案

#1


16  

Just a litle change and you got it:

只要一点点零钱,你就得到了:

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

#2


173  

UPDATE table1 t1, table2 t2
SET t1.field_to_change = t2.field_with_data
WHERE t1.field1 = t2.field2;

#3


22  

UPDATE book_details AS bd, book_details_old AS old
SET bd.live=1  
WHERE bd.isbn13=old.isbn13  
AND old.live=1;

#4


3  

To update a table from data in other table

从其他表中的数据更新表

UPDATE table1, table2 SET table1.field1 = table2.field1 where table1.id = table2.id

更新表1,表2设置表1。field1 =表二。field1表1。id = table2.id

EX.UPDATE transaction, member SET transaction.Memberid = member.memberId WHERE transaction.CardId = member.CardId;

更新事务,成员设置事务。Memberid =成员。memberId地方事务。CardId = member.CardId;

#5


-4  

To Update data From Other Table

更新来自其他表的数据。

UPDATE  tab t1
SET     t1.company_name = t2.company_name
FROM    tab t2
WHERE   t1.id = t2.id

#1


16  

Just a litle change and you got it:

只要一点点零钱,你就得到了:

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

#2


173  

UPDATE table1 t1, table2 t2
SET t1.field_to_change = t2.field_with_data
WHERE t1.field1 = t2.field2;

#3


22  

UPDATE book_details AS bd, book_details_old AS old
SET bd.live=1  
WHERE bd.isbn13=old.isbn13  
AND old.live=1;

#4


3  

To update a table from data in other table

从其他表中的数据更新表

UPDATE table1, table2 SET table1.field1 = table2.field1 where table1.id = table2.id

更新表1,表2设置表1。field1 =表二。field1表1。id = table2.id

EX.UPDATE transaction, member SET transaction.Memberid = member.memberId WHERE transaction.CardId = member.CardId;

更新事务,成员设置事务。Memberid =成员。memberId地方事务。CardId = member.CardId;

#5


-4  

To Update data From Other Table

更新来自其他表的数据。

UPDATE  tab t1
SET     t1.company_name = t2.company_name
FROM    tab t2
WHERE   t1.id = t2.id