Frank Seifert Frank Seifert -4 years ago 67
SQL Question

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


Does UNION ALL guarantee to print out records from tables b, c, d in that order? I.e., no records from c before any from b. This question is not for a specific DBMS.

Answer Source

No order by, no order guarantee whatsoever - that's for every database.

And for standard SQL, an ORDER BY is applied to the results from all the unioned queries.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download