sql中insert into select,select into,update select语句

 

--需要table1存在
--where后面可以写关联子查询条件,也可以不写,mysql中不能写t1别名
insert into table1 t1(id, name)
select id,name from table2 t2 
where t2.字段=t1.某字段;

--给项目插入全部学段,需要指定项目Id

insert into TBL_PROJECT_GRADE t1(id, project_id,grade_id)   
select lower(sys_guid()) as id,'porjectId'as project_id,value as grade_id from TBL_BASE_DICT t 
where module_id = '2'  

  db2下insert into table1后面似乎不能写别名

 

--select * into table2 from table1
--需要tmp_table不存在,新建,PL/SQL需要如下写法
create table tmp_table as
select id from tbl_project

 

 

--update select
update table1 t1 set t1.name = 
(select name from table2 t2 wehre t2.id=t1.id)  

 子查询中引用外表的值,写在where后可以,写在表连接中的on后不行。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值