SQL Server UNION - What is the default ORDER BY Behaviour

前端 未结 6 1992
生来不讨喜
生来不讨喜 2020-11-27 20:38

If I have a few UNION Statements as a contrived example:

SELECT * FROM xxx WHERE z = 1
UNION 
SELECT * FROM xxx WHERE z = 2
UNION
SELECT * FROM xxx WHERE z =         


        
6条回答
  •  感情败类
    2020-11-27 21:07

    It's very common to come across poorly written code that assumes table data is returned in insert order, and 95% of the time the coder gets away with it and is never aware that this is a problem as on many common databases (MSSQL, Oracle, MySQL). It is of course a complete fallacy and should always be corrected when it's come across, and always, without exception, use an Order By clause yourself.

提交回复
热议问题