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

所属分类: 数据库 / Mysql 阅读数: 1024
收藏 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 行转列和列转行实例详解

这篇文章主要介绍了mysql 行转列和列转行实例详解的相关资料,需要的朋友可以参考下
收藏 0 赞 0 分享

Mysql更换MyISAM存储引擎为Innodb的操作记录总结

下面小编就为大家带来一篇Mysql更换MyISAM存储引擎为Innodb的操作记录总结。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

MACOS中忘记MySQL root密码的解决方案

这篇文章主要向大家讲述的是在MAC系统中MySQL重设root密码的实际操作步骤,在实际操作中忘记MySQL root密码时常会发生的,下面就是本教程的详细内容介绍。
收藏 0 赞 0 分享

MySQL修改默认存储引擎的实现方法

下面小编就为大家带来一篇MySQL修改默认存储引擎的实现方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Mysql数据库之Binlog日志使用总结(必看篇)

下面小编就为大家带来一篇Mysql数据库之Binlog日志使用总结(必看篇)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

浅谈mysql密码遗忘和登陆报错的问题

下面小编就为大家带来一篇浅谈mysql密码遗忘和登陆报错的问题。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

mysql完整备份时过滤掉某些库的方法

下面小编就为大家带来一篇mysql完整备份时过滤掉某些库的方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

mysqldump备份数据库时排除某些库的实例

下面小编就为大家带来一篇mysqldump备份数据库时排除某些库的实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

完美解决mysql客户端授权后连接失败的问题

下面小编就为大家带来一篇完美解决mysql客户端授权后连接失败的问题。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

MySQL修改root密码的多种方法(推荐)

本文给大家分享了三种方法来解决mysql修改root密码的方法,非常不错,具有参考借鉴价值,需要的朋友参考下吧
收藏 0 赞 0 分享
查看更多