服务器之家

服务器之家 > 正文

mysql多表join时候update更新数据的方法

时间:2019-11-16 16:12     来源/作者:MYSQL教程网

sql语句:

复制代码代码如下:


update item i,resource_library r,resource_review_link l set i.name=CONCAT('Review:',r.resource_name) where i.item_id=l.instance_id 
and l.level='item' and r.resource_id=l.resource_id and i.name='' 



JOIN UPDATE & JOIN DELETE 

复制代码代码如下:


update a 
set a.schoolname = b.schoolname 
from tb_Std as a join tb_Sch as b on a.School = b.School 
where a.std_year = 2005 
go 
/* 
(2 row(s) affected) 
*/ 
select * 
from tb_Std as a join tb_Sch as b on a.School = b.School 
/* 
A School A A School 
2 2005 A A School A A School 
3 2004 C A School C C School 
4 2005 D D School D D School 
(4 row(s) affected) 
*/ 

 

复制代码代码如下:


delete a 
from table1 a, table2 b 
where a.col1 = b.col1 
and a.col2 = b.col2 


The above SQL statement runs fine in SQL Server. 
If the Oracle 9i has different syntax or if there is any other way to accomplish this with a single delete statement that would be really helpful. 

> Hi, 

> Is the following delete statement possible in Oracle 9i. 

> delete a 
> from table1 a, table2 b 
> where a.col1 = b.col1 
> and a.col2 = b.col2 

> The above SQL statement runs fine in SQL Server. 

> If the Oracle 9i has different syntax or if there is any other way to accomplish this with a single delete statement that would be really helpful. 

> Thanx in advance. 

> -Bheem 
Bheem, 
Try this: 
DELETE FROM table1 a where exists (select 1 from table2 b 
where a.col1 = b.col1 and a.col2 = b.col2); 
Hope this helps, 
Tom K.

 

相关文章

热门资讯

玄元剑仙肉身有什么用 玄元剑仙肉身境界等级划分
玄元剑仙肉身有什么用 玄元剑仙肉身境界等级划分 2019-06-21
男生常说24816是什么意思?女生说13579是什么意思?
男生常说24816是什么意思?女生说13579是什么意思? 2019-09-17
配置IIS网站web服务器的安全策略配置解决方案
配置IIS网站web服务器的安全策略配置解决方案 2019-05-23
Nginx服务器究竟是怎么执行PHP项目
Nginx服务器究竟是怎么执行PHP项目 2019-05-24
运维必须知道的关于云服务器的十个问题
运维必须知道的关于云服务器的十个问题 2019-05-24
返回顶部