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

时间:2024-01-15 12:56:37 

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.

标签:join,update
0
投稿

猜你喜欢

  • javascript事件冒泡,事件捕获和事件委托详解

    2024-04-10 14:02:47
  • 如何将txt文本中的数据轻松导入MySQL表中

    2009-03-06 17:35:00
  • JavaScript模板解析演示实例

    2009-10-19 23:16:00
  • Python基于内置库pytesseract实现图片验证码识别功能

    2022-05-26 07:40:53
  • MySQL慢sql优化思路详细讲解

    2024-01-18 03:51:43
  • mysql双向加密解密方式用法详解

    2024-01-15 05:55:02
  • 为FCKeditor2.6添加行距功能(最新修改)

    2008-08-18 21:09:00
  • 嵌入Flash应该考虑不支持Flash的浏览器

    2007-12-20 12:29:00
  • Django小白教程之Django用户注册与登录

    2022-01-14 10:30:06
  • Golang Gin 中间件 Next()方法示例详解

    2024-02-20 07:29:22
  • Mysql命令大全(完整版)

    2024-01-13 15:03:35
  • python 安装virtualenv和virtualenvwrapper的方法

    2023-04-23 11:27:33
  • python数据类型强制转换实例详解

    2022-02-08 05:22:43
  • 商品评论的设计

    2009-12-23 13:06:00
  • 仿豆瓣分页原型(Javascript版)

    2007-11-05 14:04:00
  • Dreamweaver MX弹出窗口全攻略

    2010-09-05 21:14:00
  • numpy中hstack vstack stack concatenate函数示例详解

    2023-02-22 19:39:06
  • Python爬虫之UserAgent的使用实例

    2022-03-10 15:41:39
  • 理解Sql Server中的聚集索引

    2024-01-23 11:51:46
  • Python3 常用数据标准化方法详解

    2022-08-02 01:51:31
  • asp之家 网络编程 m.aspxhome.com