SQL中同时修改两个表里的字段

来源:百度知道 编辑:UC知道 时间:2024/05/22 11:09:26
同时修改两个表里的字段
如:t1 表(a,b)
t2 表(a,c)
我现在想要一条语句时间修改t1,t2表中的b,c两个字段
请看好是一条语句

各位大哥帮帮忙吧!谢谢!
嵌套?
怎么嵌套我现在就是没想明白这个事
能写具体点吗?

我就是不知道才问的嘛,知道我就不问了.

嘿嘿,本来也以为UPDATE 语句只可以对单表操作,
后来还是查了一下,发现MYSQL 可以对多表更新:
13.2.10. UPDATE Syntax
单表更新的语法:
Single-table syntax:

UPDATE [LOW_PRIORITY] [IGNORE] tbl_name
SET col_name1=expr1 [, col_name2=expr2 ...]
[WHERE where_condition]
[ORDER BY ...]
[LIMIT row_count]
多表更新的语法:
Multiple-table syntax:

UPDATE [LOW_PRIORITY] [IGNORE] table_references
SET col_name1=expr1 [, col_name2=expr2 ...]
[WHERE where_condition]

单表就不说了,下面讲讲多表:
For the multiple-table syntax, UPDATE updates rows in each table named in table_references that satisfy the conditions. In this case, ORDER BY and LIMIT cannot be used.

要英文不好看就看看例子吧:
UPDATE items,month SET items.price=month.price
WHERE items.id=month.id;

讲讲table_references:
其实就是一个连接方式:join;

你要多表做更新操作,肯定要把表关联起来。

你的例子中:
mysql> insert into abc(a) values('1');
Query OK, 1 row affecte