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

所属分类: 数据库 / Mysql 阅读数: 962
收藏 0 赞 0 分享
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.
更多精彩内容其他人还在看

mysql jdbc连接步骤及常见参数

这篇文章主要介绍了mysql jdbc连接步骤及常见参数,需要的朋友可以参考下
收藏 0 赞 0 分享

Navicat for MySQL(mysql图形化管理工具)是什么?

这里就给大家介绍一个常用的MySQL数据库管理工具:Navicat for MySQL,需要的朋友可以参考下
收藏 0 赞 0 分享

lnmp下如何关闭Mysql日志保护磁盘空间

这篇文章主要介绍了lnmp下如何关闭Mysql日志保护磁盘空间的相关资料,需要的朋友可以参考下
收藏 0 赞 0 分享

使用phpMyAdmin批量修改Mysql数据表前缀的方法

这篇文章主要介绍了使用phpMyAdmin批量修改Mysql数据表前缀的方法,需要的朋友可以参考下
收藏 0 赞 0 分享

如何解决局域网内mysql数据库连接慢

通过内网连另外一台机器的mysql服务, 确发现速度N慢! 等了大约几十秒才等到提示输入密码。非常急人,有没有办法可以解决局域网内mysql数据库连接慢呢?下面小编带领大家来解决此问题,感兴趣的朋友一起看看吧
收藏 0 赞 0 分享

使用SKIP-GRANT-TABLES 解决 MYSQL ROOT密码丢失

这篇文章主要介绍了使用SKIP-GRANT-TABLES 解决 MYSQL ROOT密码丢失的相关资料,需要的朋友可以参考下
收藏 0 赞 0 分享

MySQL 5.0.16乱码问题的解决方法

这篇文章主要介绍了MySQL 5.0.16乱码问题的解决方法,需要的朋友可以参考下
收藏 0 赞 0 分享

MySQL提高分页效率

本文分享的这段代码是大数据量时提高分页的效率的测试代码,感兴趣的小伙伴可以参考一下
收藏 0 赞 0 分享

小记一次mysql主从配置解决方案

mysql主从方案主要作用:读写分离,使数据库能支撑更大的并发。在报表中尤其重要。由于部分报表sql语句非常的慢,导致锁表,影响前台服务。如果前台使用master,报表使用slave,那么报表sql将不会造成前台锁,保证了前台速度。
收藏 0 赞 0 分享

RHEL6.5编译安装MySQL5.6.26教程

这篇文章主要介绍了RHEL6.5编译安装MySQL5.6.26教程的相关资料,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多