Select Distinct without sorting

distinct, ms-access, sql

Solution

I'll try to elaborate a bit as to what's going on and why... though I agree with @vic's comment to the question...

- Without explicitly stating an order (via an `order by` clause) there is absolutely no guarantee of any order in the result set.

- Practically speaking, many queries will return a consistent order based on the query plan and how the data is actually stored and accessed... DO NOT RELY ON THIS!

- Specifically, for a `distinct` query, the sql engine will sort the data so that it can be sure to remove any duplicates.

In short, if the order of the result set matters (even if the desired order is "random") you must ALWAYS explicitly state it. That said, from a purely set-based-math/sql standpoint, the order of the result shouldn't matter.

Problem

I used a Select Distinct query, which resulted me a sorted data. Is there anyway that i dont get data sorted?

Original source