union命令作用:连接两个以上的 SELECT 语句的结果组合到一个表中

一. 示例:

select id, url, auth_status as authStatus, enterprise_name as enterpriseName, establish_time as establishTime, 'node' as  type, null as messageId, null as sender, created_time from node where node_role != 'SELF'
union
select id , null as url, null as authStatus, null as enterpriseName, null as establishTime, 'message' as type, id as messageId, sender,created_time from message where `message_type`='INVITE' and handled=0 order by created_time desc

注意事项:

1. 两表字段长度需要一致

2. order by 排序的字段,需要在查询字段中包含

3. union 合并时默认去重,若不需要去重,可以使用union all

二.获取链表查询的数量总和

select sum(a.b) as num from (
select count() as b from table_1
union all
select count() as b from table_2
) as a(注意这里要取个别名)

最新文章

  1. Centos 7防火墙firewalld开放80端口(转)
  2. Markdown编辑器简单总结
  3. MySQL模拟:线上误update的恢复
  4. SQL Server xtype
  5. HDU 4897 Little Devil I(树链剖分)(2014 Multi-University Training Contest 4)
  6. 544B. Sea and Islands
  7. 1.5.5 Tokenizers
  8. jar包冲突解决方法
  9. Android 签名(2)签名知识要点
  10. python中的字典(dict),列表(list),元组(tuple)
  11. 对c#剪切板Clipboard占用的问题一点解决方法
  12. Linux下find命令具体解释
  13. uva 10635 Prince and Princess(LCS成问题LIS问题O(nlogn))
  14. 三分钟浅谈TT猫的前端优化
  15. zzuli 2130: hipercijevi 链式前向星+BFS+输入输出外挂
  16. Redis-04.备份与恢复
  17. drf开发中常见问题
  18. layui loading
  19. JAVA核心技术I---JAVA基础知识(时间类)
  20. excel vba获取拼音

热门文章

  1. 23年用vuex进行状态管理out了,都开始用pinia啦!
  2. Golang make和new的区别及实现原理详解
  3. ABAP 拼接PDF
  4. Linux - tar 命令详解 (压缩,解压,加密压缩,解密压缩)
  5. Java实现简单薪水计算器相关操作代码
  6. ORACLE 遇到ORA-31693 ORA-31617 ORA-19505 ORA-27037
  7. java之路总结
  8. java SE01
  9. MapReduce原理——Shuffle机制
  10. docker容器部署flask单页面应用