sql 查询结果合并union all用法_数据库技巧

2023年 4月 17日 65.5k 0

复制代码 代码如下: --合并重复行 select * from A union select * from B --不合并重复行 select * from A union all select * from B 按某个字段排序 --合并重复行 select * from ( select * from A union select * from B)

复制代码 代码如下:--合并重复行 select * from A union select * from B --不合并重复行 select * from A union all select * from B 按某个字段排序 --合并重复行 select * from ( select * from A union select * from B) AS T order by 字段名 --不合并重复行 select * from ( select * from A union all select * from B) AS T order by 字段名 //sql server版 Select * From ( select top 2 id,adddate,title,url from bArticle where ClassId=1 order by adddate desc) A Union All Select * From ( select top 2 id,adddate,title,url from bArticle where ClassId=2 order by adddate desc) B Union All Select * From ( select top 2 id,adddate,title,url from bArticle where ClassId=3 order by adddate desc) C Union All Select * From ( select top 2 id,adddate,title,url from bArticle where ClassId=4 order by adddate desc) D //mysql版 Select * From ( select id,adddate,title,url from bArticle where ClassId=1 order by adddate desc limit 0,2) A Union All Select * From ( select id,adddate,title,url from bArticle where ClassId=2 order by adddate desc limit 0,2) B Union All Select * From ( select id,adddate,title,url from bArticle where ClassId=3 order by adddate desc limit 0,2) C Union All Select * From ( select id,adddate,title,url from bArticle where ClassId=4 order by adddate desc limit 0,2) D

相关文章

Oracle如何使用授予和撤销权限的语法和示例
Awesome Project: 探索 MatrixOrigin 云原生分布式数据库
下载丨66页PDF,云和恩墨技术通讯(2024年7月刊)
社区版oceanbase安装
Oracle 导出CSV工具-sqluldr2
ETL数据集成丨快速将MySQL数据迁移至Doris数据库

发布评论