欢迎来到天天文库
浏览记录
ID:34750513
大小:56.18 KB
页数:3页
时间:2019-03-10
《合并union和unionall用法sql结果》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、合并union和unionall用法-sql语句查询结果--合并重复行select*fromAunionselect*fromB--不合并重复行select*fromAunionallselect*fromB按某个字段排序--合并重复行select*from(select*fromAunionselect*fromB)ASTorderby字段名--不合并重复行select*from(select*fromAunionallselect*fromB)ASTorderby字段名//sqlserver版Select*From(selecttop2id,add
2、date,title,urlfrombArticlewhereClassId='1'orderbyadddatedesc)AUnionAllSelect*From(selecttop2id,adddate,title,urlfrombArticlewhereClassId='2'orderbyadddatedesc)BUnionAllSelect*From(selecttop2id,adddate,title,urlfrombArticlewhereClassId='3'orderbyadddatedesc)CUnionAllSelect*From(s
3、electtop2id,adddate,title,urlfrombArticlewhereClassId='4'orderbyadddatedesc)D//mysql版Select*From(selectid,adddate,title,urlfrombArticlewhereClassId='1'orderbyadddatedesclimit0,2)AUnionAllSelect*From(selectid,adddate,title,urlfrombArticlewhereClassId='2'orderbyadddatedesclimit0,2
4、)BUnionAllSelect*From(selectid,adddate,title,urlfrombArticlewhereClassId='3'orderbyadddatedesclimit0,2)CUnionAllSelect*From(selectid,adddate,title,urlfrombArticlewhereClassId='4'orderbyadddatedesclimit0,2)D在DB2里使用union时一定要注意相对应的字段一定是数据类型一样,输出时可以任意显示的列,但不能输出不同类型或不同表结构。因为这样会出错。
此文档下载收益归作者所有