sql 查詢結(jié)果合并union all用法_數(shù)據(jù)庫技巧
--合并重復(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
相關(guān)文章
SQL CONVERT轉(zhuǎn)化函數(shù)使用方法小結(jié)
此樣式一般在時(shí)間類型(datetime,smalldatetime)與字符串類型(nchar,nvarchar,char,varchar) 相互轉(zhuǎn)換的時(shí)候才用到.2010-05-05SQL Server 實(shí)現(xiàn)數(shù)字輔助表實(shí)例代碼
這篇文章主要介紹了SQL Server 實(shí)現(xiàn)數(shù)字輔助表的相關(guān)資料,并附實(shí)例代碼,需要的朋友可以參考下2016-10-10SQL 使用 VALUES 生成帶數(shù)據(jù)的臨時(shí)表實(shí)例代碼詳解
這篇文章主要介紹了SQL 使用 VALUES 生成帶數(shù)據(jù)的臨時(shí)表,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2007-09-09MSSQL差異備份取系統(tǒng)權(quán)限的相關(guān)軟件下載
MSSQL差異備份取系統(tǒng)權(quán)限的相關(guān)軟件下載...2007-11-11MyBatis SQL xml處理小于號(hào)與大于號(hào)正確的格式
這篇文章主要介紹了MyBatis SQL xml處理小于號(hào)與大于號(hào)正確的格式,需要的朋友可以參考下2018-06-06SQLServer Execpt和not in 性能區(qū)別
網(wǎng)上有很多 except 和 not in的返回結(jié)果區(qū)別這里就就提了2012-01-01五種SQL Server分頁存儲(chǔ)過程的方法及性能比較
本文主要介紹了SQL Server數(shù)據(jù)庫分頁的存儲(chǔ)過程的五種方法以及它們之間性能的比較,并給出了詳細(xì)的代碼,希望能夠?qū)δ兴鶐椭?/div> 2015-08-08sql server中datetime字段去除時(shí)間的語句
sql server中datetime字段去除時(shí)間的語句...2007-08-08SQLServer中JSON文檔型數(shù)據(jù)的查詢問題解決
SQL Server 對(duì)于數(shù)據(jù)平臺(tái)的開發(fā)者來說越來越友好,下面這篇文章主要給大家介紹了關(guān)于SQLServer中JSON文檔型數(shù)據(jù)的查詢問題的解決方法,需要的朋友可以參考下2021-06-06最新評(píng)論