[英]Does table1 UNION ALL table2 guarantee output order table1, table2?
SELECT a FROM b
UNION ALL
SELECT a FROM c
UNION ALL
SELECT a FROM d
UNION ALL是否保證按順序打印表b,c,d中的記錄? 即,在b之前沒有來自c的記錄。 這個問題不適用於特定的DBMS。
沒有訂單,沒有任何訂單保證 - 這適用於每個數據庫。
對於標准SQL,ORDER BY應用於所有聯合查詢的結果。
為了確保順序使用
Select 1 as TableNo,* from a
union all
select 2 as TableNo,* from b
union all
select 3 as TableNO,* from c
order by TableNo, [desired column]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.