MySql - Reordering the rows of a table

draco_alpine

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:

  • For performance reasons I can't create a new temporary table to store the ordered data in

  • For cleanness of the user-interface I must assume that all select statements will be without an order by clause

  • Because of the insert into mechanism I can't order the table while it's being built up

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

rlanvin

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).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

reordering mysql table rows to increase speed

From Dev

Sorting two dimensional table by reordering rows and columns

From Dev

Reordering MySQL rows based on a certain row

From Dev

Reordering MySQL rows based on a certain row

From Dev

iOS reordering table view rows without delete button

From Dev

Reordering Matrix Rows in Matlab

From Dev

Interleave rows of MySQL table

From Dev

Number of rows in a MySQL table?

From Dev

Interleave rows of MySQL table

From Dev

Table rows into columns in mysql

From Dev

Excel - reordering table

From Dev

Reordering rows in a data.frame?

From Dev

Primefaces reordering rows containing inputs

From Dev

Reordering the rows in a matrix in a specific order

From Dev

MySQL delete duplicate rows in table

From Dev

Combine multiple rows in a MySQL table

From Dev

Delete all rows in a table with MySQL?

From Dev

Mysql join table and count rows

From Dev

How to union rows on the table mysql

From Dev

Calculate number of table rows in mysql

From Dev

Sorting MySQL table and then updating the rows

From Dev

Inserting rows in the same table in MySQL

From Dev

Finding duplicate rows in a MySQL table

From Dev

update a position field by reordering a table

From Dev

Converting a table column into table rows using MySQL

From Dev

Join rows of table A with columns of table B in MySQL

From Dev

mysql join two table rows in one table

From Dev

MySQL: Update rows in table, from rows with matching key in another table

From Dev

MySQL: Clone multiple rows in Table A and related rows in Table B