draco_alpine
draco_alpine

Reputation: 785

MySql - Reordering the rows of a table

I have a table (with no PK) that is being inserted into by an regular event. It is currently unordered, and I would like to order it in the fashion of

select * from t1 order by col1 ASC,col2 DESC

Constraints are as follows:

Is there some way of doing this that I don't know about/have overlooked?

Upvotes: 2

Views: 80

Answers (1)

rlanvin
rlanvin

Reputation: 6267

Is there some way of doing this that I don't know about/have overlooked?

No. And here is a very good explanation. Quoting the most revelant part:

In the SQL world, order is not an inherent property of a set of data. Thus, you get no guarantees from your RDBMS that your data will come back in a certain order -- or even in a consistent order -- unless you query your data with an ORDER BY clause.

That being said, if you remove your performance requirements, you could create an ordered view and select from it. For example (not sure about the syntax):

CREATE VIEW foobar AS
select * from t1 order by col1 ASC,col2 DESC;

But it's going to be slow(ish).

Upvotes: 4

Related Questions