Why do results from a SQL query not come back in the order I expect?

前端 未结 2 2059
野性不改
野性不改 2020-11-27 07:56

If items are inserted in a table, and then I write a query, such as select * from table, why are the results not in the order that I expect?

2条回答
  •  失恋的感觉
    2020-11-27 08:49

    It is a common misconception to expect results in the order that is inserted. Even when a clustered index is used, the result set may not be as expected. Only way to force an order is to use an "order by" clause. The reason that the order is different from what is expected may vary. The query may be executed in parallel and the result set may be merged or it may be due to the query optimization plan while trying to return the result set as fast as possible.

提交回复
热议问题