MySQL 用另一个表中的数据更新mysql表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/414828/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Update mysql table with data from another table
提问by William Macdonald
Is it possible to run an UPDATE command on mysql 5.0 with a sub select.
是否可以使用子选择在 mysql 5.0 上运行 UPDATE 命令。
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
威廉
采纳答案by Ricardo Acras
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);
回答by MCurbelo
UPDATE table1 t1, table2 t2
SET t1.field_to_change = t2.field_with_data
WHERE t1.field1 = t2.field2;
回答by Rob
UPDATE book_details AS bd, book_details_old AS old
SET bd.live=1
WHERE bd.isbn13=old.isbn13
AND old.live=1;
回答by luxknight_007
To update a table from data in other table
从其他表中的数据更新表
UPDATE table1, table2 SET table1.field1 = table2.field1 where table1.id = table2.id
UPDATE table1, table2 SET table1.field1 = table2.field1 where table1.id = table2.id
EX.UPDATE transaction, member SET transaction.Memberid = member.memberId
WHERE transaction.CardId = member.CardId;
前任。UPDATE transaction, member SET transaction.Memberid = member.memberId
WHERE transaction.CardId = member.CardId;
回答by Dinesh Guptha
To Update data From Other Table
从其他表更新数据
UPDATE tab t1
SET t1.company_name = t2.company_name
FROM tab t2
WHERE t1.id = t2.id