Is this a Bug in the ORDER BY?
The UNION behaves as expected, whereas the UNION ALL does not. I know UNION has an additional step where it gets rid of duplicates; but I can't understand why they sort differently. Does anyone have an explanation for this?
-- UNION ALL ORDER BY Bug
SELECT SPACE(1) AS [sp], 1 UNION ALL
SELECT SPACE(2), 2 UNION ALL
SELECT SPACE(5), 5 UNION ALL
SELECT SPACE(4), 4 UNION ALL
SELECT SPACE(0), 0
ORDER BY [sp]
SELECT SPACE(1) AS [sp], 1 UNION
SELECT SPACE(2), 2 UNION
SELECT SPACE(5), 5 UNION
SELECT SPACE(4), 4 UNION
SELECT SPACE(0), 0
ORDER BY [sp]
![alt text][1]
[1]: /storage/temp/2163-union-all-order-by-bug.jpg
↧