1. 通过关联字段把一张表的字段值更新另一张表的字段值

update table_a a, table_b b set a.username = b.username where a.id = b.id;

-- 以下2种更新结果以table_b的查询结果为准,table_b中没有查到的记录会全部被更新为null,相当于外连接
update table_a a set username = (select name from table_b where id = a.id);
update table_a a left join table_b b on a.id= b.id set a.username = b.name; 

2. 将查询结果插入另一张表

-- insert into 表1(列名) select 列名 from 表2;
insert into table_a(username) select name from table_b where id=1;

3. with tab as...

  属于子查询的一种解决方案---公用表表达式(CTE), 使用该语法必须注意:

-- 1. CTE后面必须直接跟使用CTE的SQL语句(如select、insert、update等), 否则, CTE将失效. with 
tab as (
  select user_code from table_a where user_code like '%ad%'
)
select * from table_b where user_code in (select * from tab)
-- 2. CTE后面也可以跟其他的CTE, 但只能使用一个with, 多个CTE中间用逗号(,)分隔.
with
tab1 as(
  select * from table_a where name like '赵%'
),
tab2 as(
  select * from table_b where age> 20
),
tab3 as(
  select * from table_c where gender = 0
)
select a.* from tab1 a, tab2 b, tab3 c where a.id = b.id and a.id = c.id

4. 待更新

最新文章

  1. EF6 CodeFirst+Repository+Ninject+MVC4+EasyUI实践(六)
  2. 黑马程序员----java基础笔记上(毕向东)
  3. 2、Linux系统root用户忘记密码的重置方式
  4. Java web--反射(解刨)
  5. MAC OS设置JDK小结
  6. Arch时间校准
  7. 使用Quartz创建定时任务
  8. LInux系统及其文件系统
  9. UVa 740 - Baudot Data Communication Code
  10. jsp容易混淆的知识点
  11. 部署Openfire3.9.3源码部署
  12. 探究编译后,try-with-resources括号中的object是否关闭,以及两种写法编译后的对比
  13. 前端 -----函数和伪数组(arguments)
  14. JDK自带的运行监控工具JConsole观察分析Java程序的运行
  15. 《Redis 持久化》
  16. [转载]谈谈document.ready和window.onload的区别
  17. C#的Lambda表达式嵌套例子
  18. Python标准库学习之zipfile模块
  19. 腾讯云服务器linux Ubuntu操作系统搭建ftp服务器vsftpd
  20. C#互操作

热门文章

  1. 行为型模式 - 命令模式Command
  2. 真正“搞”懂HTTP协议11之代理服务
  3. 重学SpringBoot. step6 SpringBoot高级技巧
  4. mysql03-默认的几个数据库
  5. C语言排序 冒泡 选择 快排
  6. JZOJ 4270.【NOIP2015模拟10.27】魔道研究
  7. Android:Activity
  8. 在 WXML 中使用 JS 代码
  9. 剖析flutter_download_manager学习如何做下载管理,暂停和取消
  10. NOIP 2022 游记