主頁 > 知識(shí)庫 > sql 查詢結(jié)果合并union all用法_數(shù)據(jù)庫技巧

sql 查詢結(jié)果合并union all用法_數(shù)據(jù)庫技巧

熱門標(biāo)簽:呼叫中心市場需求 鐵路電話系統(tǒng) 地方門戶網(wǎng)站 服務(wù)外包 網(wǎng)站排名優(yōu)化 AI電銷 百度競價(jià)排名 Linux服務(wù)器
復(fù)制代碼 代碼如下:

--合并重復(fù)行
select * from A
union
select * from B


--不合并重復(fù)行
select * from A
union all
select * from B


按某個(gè)字段排序
--合并重復(fù)行
select *
from (
select * from A
union
select * from B) AS T
order by 字段名

--不合并重復(fù)行
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
您可能感興趣的文章:
  • sql Union和Union All的使用方法
  • sqlserver Union和SQL Union All使用方法
  • Sql學(xué)習(xí)第一天——SQL UNION 和 UNION ALL 操作符認(rèn)識(shí)
  • Mysql聯(lián)合查詢UNION和UNION ALL的使用介紹
  • MySQL中使用or、in與union all在查詢命令下的效率對(duì)比
  • SQL語句之Union和Union All的用法

標(biāo)簽:銅川 衡水 湖南 蘭州 湘潭 黃山 崇左 仙桃

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《sql 查詢結(jié)果合并union all用法_數(shù)據(jù)庫技巧》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266