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

发布于 2024-07-11 10:33:41 字数 271 浏览 4 评论 0原文

是否可以使用子选择在 mysql 5.0 上运行 UPDATE 命令。

我想运行的命令是这样的:

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

ISBN13 当前存储为字符串。

这应该更新 10k+ 行。

谢谢,

威廉

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

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.

This should be updating 10k+ rows.

Thanks,

William

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

半﹌身腐败 2024-07-18 10:33:41
UPDATE table1 t1, table2 t2
SET t1.field_to_change = t2.field_with_data
WHERE t1.field1 = t2.field2;
UPDATE table1 t1, table2 t2
SET t1.field_to_change = t2.field_with_data
WHERE t1.field1 = t2.field2;
旧人九事 2024-07-18 10:33:41
UPDATE book_details AS bd, book_details_old AS old
SET bd.live=1  
WHERE bd.isbn13=old.isbn13  
AND old.live=1;
UPDATE book_details AS bd, book_details_old AS old
SET bd.live=1  
WHERE bd.isbn13=old.isbn13  
AND old.live=1;
无声静候 2024-07-18 10:33:41

只需一点点改变,你就得到了它:

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

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);
淡淡の花香 2024-07-18 10:33:41

从另一个表中的数据更新一个表:

UPDATE table1, table2
SET table1.field1 = table2.field1
WHERE table1.id = table2.id;

例如:

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

To update a table from data in another table:

UPDATE table1, table2
SET table1.field1 = table2.field1
WHERE table1.id = table2.id;

For example:

UPDATE transaction, member
SET transaction.Memberid = member.memberId
WHERE transaction.CardId = member.CardId;
つ可否回来 2024-07-18 10:33:41

从其他表更新数据

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

To Update data From Other Table

UPDATE  tab t1, tab t2
SET     t1.company_name = t2.company_name
WHERE   t1.id = t2.id
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文