我有這兩個查詢。在MySQL中的聯合查詢
select * from blog_post where isDelete=0
and pOrder !=0 order by pOrder asc
select * from blog_post where isDelete=0
and pOrder=0 order by postID desc
這工作正常。
但是當我嘗試加入這個兩個查詢到union
,
select * from
((select * from blog_post
where isDelete=0 and pOrder !=0
order by pOrder asc)
union all
(select * from blog_post
where isDelete=0 and pOrder=0
order by postID desc)) as tbl1
它給第二個查詢的升序輸出,但在查詢它是按降序排列。
在你的查詢pOrder和postID是不同的列..? – Hrithu
是它的不同列 –