Reputation: 143
I have a table, where one column is sorted. Does MySQL somehow check if it's sorted or not? If I make such a query SELECT from tab WHERE col1>890 AND col1<74893798
where the col1 is sorted, is it the same as e.g. SELECT from tab WHERE id>16 AND id<798176
I was unable to test this properly because of lack of admin rights to flush the query cache.
To make it clear, the col1 is sorted, because it was inserted there from another table which had been sorted by the column.
Upvotes: 0
Views: 48
Reputation: 6418
MySQL does not sort results by default (What drive the natural result order for an unordered MySQL request). Generally, Relational DataBase Management Systems (RDBMS) do not guarantee any specific row order unless you specify an order with an ORDER BY clause.
The advantage of this is that the database may internally sort data in whatever format it deems to be most optimal.
Upvotes: 1
Reputation: 2755
No, it is not sorted by the column you use on your where clause. The id
records look sorted because that's probably your primary key and already dictates the position of the data in your table. You need to add ORDER BY column
if you want your data sorted
Upvotes: 1