首页 > 代码库 > sql语句查询结果合并union all用法_数据库技巧
sql语句查询结果合并union all用法_数据库技巧
--合并重复行select * from Aunion select * from B--不合并重复行select * from Aunion allselect * from B按某个字段排序--合并重复行select *from (select * from Aunion select * from B) AS Torder by 字段名--不合并重复行select *from (select * from Aunion allselect * from B) AS Torder by 字段名//sql server版Select * From (select top 2 id,adddate,title,url from bArticle where ClassId=1 order by adddate desc) AUnion AllSelect * From (select top 2 id,adddate,title,url from bArticle where ClassId=2 order by adddate desc) BUnion AllSelect * From (select top 2 id,adddate,title,url from bArticle where ClassId=3 order by adddate desc) CUnion AllSelect * 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) AUnion AllSelect * From (select id,adddate,title,url from bArticle where ClassId=2 order by adddate desc limit 0,2) BUnion AllSelect * From (select id,adddate,title,url from bArticle where ClassId=3 order by adddate desc limit 0,2) CUnion AllSelect * From (select id,adddate,title,url from bArticle where ClassId=4 order by adddate desc limit 0,2) D
sql语句查询结果合并union all用法_数据库技巧
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。