What is the order of selecting data from a database?

Suppose I have a table:

CREATE TABLE [tab] (
    [name] varchar,
    [order_by] int
)

There are 10 rows in the table, and all rows have the same value for order_by (let them say 0)

If I then issue the following SQL:

select * from [tab] order by [order_by]

What is the order of the lines? What factor determines the order of the lines in this case?

+3
source share
8 answers

It is not defined. The database can spit them out in any order it chooses, and it can even change the order between queries if it looks like this (it probably won't, but you shouldn't rely on a consistent order).

+8
source

If your columns that you order do not have any changes than there is no guaranteed order.

, , order by good order by. , - orderby, , .

+6

, .

+4

, - ( , , ), , . , .

+1

, , , order by, sames order by .

, , . . , . , . , . SQL Server , .

+1

PKey. , SQL Server 2008. , SQL Server, , OLEDB ODBC.

0

"" , ( ASC, DESC). , , , . , , SQL 2008.

"" , , .

EDIT:

, , , , . : SQL

, , , .

0

"" - , CLUSTERED , , , , . , , , , , .

If you specify the order and the key that you order is equal for a group of strings, then the order is not guaranteed at all.

0
source

Source: https://habr.com/ru/post/1731086/


All Articles