Ashwin_DSA
Databricks Employee
Databricks Employee

Hi @IM_01,

Not exactly... You don’t need another view/table to "bake in" the order, and even if you did, it still wouldn’t guarantee ordered results.

As I mentioned in my earlier reply, tables and materialized views never guarantee row order. ORDER BY only guarantees order for the specific SELECT that contains it. SELECT * FROM some_mv; has no guaranteed order, no matter how the MV was created. That applies to plain Delta tables. Wrapping in another view doesn’t fix it either.

For example, if you did something like the below...

 

CREATE VIEW sorted_v AS
SELECT * FROM my_mv ORDER BY some_col;
-- Later tried to query 
SELECT * FROM sorted_v;   -- order NOT guaranteed
 
The outer query can reorder rows unless it has ORDER BY. So, the correct pattern is always order at query time:
SELECT *
FROM my_mv
ORDER BY some_col;
 

The reliable approach is not an extra MV/table. It’s ordering in every SELECT that needs sorting.

If this answer resolves your question, could you mark it as “Accept as Solution”? That helps other users quickly find the correct fix.

Regards,
Ashwin | Delivery Solution Architect @ Databricks
Helping you build and scale the Data Intelligence Platform.
***Opinions are my own***