【SQL】DML语句-SQL更新与删除:单表更新删除与连表更新删除语法

〇、概述

1、资料

sql连表删除:http://www.lanxinbase.com/?tag=sql%E8%BF%9E%E8%A1%A8%E5%88%A0%E9%99%A4

sql实现两表关联更新:https://blog.csdn.net/qq_43429919/article/details/124036257

2、组成

 

一、更新操作

(一)传统方式

Update student Set Sage=22
Where Sno=’201215121’;

(二)连表方式

1、pgsql

UPDATE (要更新的表) table1 t1
SET 字段1 = t2.字段1, 字段2 = t2.字段2,
FROM
    (数据来源表) table2 t2
WHERE
    t1.key = t2.key
    
如:
update ap.xxxxxxxxx t1
set xc1=t2.qt
from (select 
	yc2,
	max(yc3) qt
from ap.yyyyyyyyyyyyy
group by yc2
) t2
where t1.xc2=t2.yc2

2、MySQL

UPDATE  (要更新的表)  table1 t1, table2 t2
SET t1.字段1 = t2.字段1, t1.字段2 = t2.字段2,
WHERE
    t1.key = t2.key

3、Oracle

update SORDER a
set a.AUUID_0=(SELECT rawtohex(b.AUUID_0) FROM SORDER b where a.AUUID_0=b.AUUID_0)

二、删除操作

(一)传统方式

Delete From SC Where Son in(
Selete Sno From Student
Where Sdept=’CS’);

(二)连表方式

delete FROM `t1` using `t1`
left join `t2` on t1.id= t2.id
where 1 and t2.id is null;

 

posted @ 2022-08-15 22:46  哥们要飞  阅读(68)  评论(0编辑  收藏  举报