MySQL 插入和连接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1382842/
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
MySQL Insert & Joins
提问by iceangel89
i saw this
我看见了这个
In MySQL, joins work for INSERT, UPDATE, and DELETE statements. It's possible to change data in more than one table when joining tables in an UPDATE or DELETE statement.
在 MySQL 中,连接适用于 INSERT、UPDATE 和 DELETE 语句。在 UPDATE 或 DELETE 语句中连接表时,可以更改多个表中的数据。
in an answer for a question from the mysql certification guide. is it true? inserts with joins? an example of it?
在回答 mysql 认证指南中的问题时。这是真的吗?插入连接?一个例子吗?
回答by Marius
You can INSERT ... SELECT with mysql, which is probably what they mean. For example:
你可以 INSERT ... SELECT with mysql,这可能就是他们的意思。例如:
INSERT INTO tableNew (col1, col2)
SELECT tbl1.col1, tbl2.col2
FROM tbl1 JOIN tbl2
回答by bobince
To complete the set, here's one for DELETE. This is a common method for deleting rows together with their dependencies without triggers.
要完成该集,这里有一个用于 DELETE。这是在没有触发器的情况下删除行及其依赖项的常用方法。
DELETE users, comments
FROM users JOIN comments ON comments.author=users.id
WHERE users.isspammer=1
回答by Paulraj
You can do this for Update statement like this,
您可以为这样的 Update 语句执行此操作,
Update C
Join tableB B on B.id=C.bid
Join tableA A on A.id=B.aid
Set C.status='Active',
A.status='Active'
Where A.id=1 or A.id=2 or A.id=3
check this for your reference.
检查此供您参考。
http://www.siusic.com/wphchen/mysql-update-statement-159.html
http://www.siusic.com/wphchen/mysql-update-statement-159.html