here's a demo
Yano is of course correct about order not being guaranteed without an order by. This has been written about 6 trillion times across the span of the internet for most if not all of the major relational database systems.
One of the really tricky things is when you're dealing with parallel execution plans, and/or ordering by non-determinsitic columns.
Contextually, I'm running SQL Server 2022, in a database using compatibility level 160. I have MAXDOP set to 8, and Cost Threshold For Parallelism set to 50.
This should produce a table populated with around 5 million rows.
CREATE TABLE
dbo.disordered
(
id bigint NOT NULL PRIMARY KEY,
random_dates date
);
INSERT
dbo.disordered WITH (TABLOCK)
(
id,
random_dates
)
SELECT
id = ROW_NUMBER() OVER (ORDER BY @@SPID),
random_dates = DATEADD(DAY, x.severity, SYSDATETIME())
FROM
(
SELECT
m.*
FROM sys.messages AS m
CROSS APPLY
(
SELECT TOP (15)
m2.*
FROM sys.messages AS m2
) AS m2
) AS x;
Here are a couple queries where running them repeatedly will produce results in different orders.
non-deterministic ordering
SELECT TOP (100)
d.*
FROM dbo.disordered AS d
ORDER BY
d.random_dates;
You should see a parallel plan for this. If you don't, the issue may not present itself.

Here are a couple examples of the results changing:

different results with no ordering
SELECT TOP (500000)
d.*
FROM dbo.disordered AS d
WHERE EXISTS
(
SELECT
1/0
FROM dbo.disordered AS d2
WHERE d.random_dates >= d2.random_dates
);
Again, you should see a parallel plan for this:

And here are examples of some differently-ordered results:

two different problems
Of course, the problem isn't parallelism, the problem is that we asked for results to be orered:
- By a non-unique column
- With no ordering whatsoever
We could solve the problem by adding a unique column to the order by clause as a secondary (tie-breaking) ordering element. The underlying message is just an extension of what Yano said: ordering isn't guaranteed without an order by clause, and is also not guaranteed when a unique tie-breaker is not included in the order by clause.