0

when I using select command without order by sub-command:

select acolumn from table

The result sequence is order by id column asc as default( or in the sequence that the record was inserted into the table, I am not sure). but I want it order by desc without order by sub-command.

I tried create desc index on id column, it does not help.

Is there anyway to achieve this?

Any help is appreciated. Thanks.

waitsummer
  • 43
  • 2
  • 8

2 Answers2

3

No, that can't be done.

Your current query doesn't return the items ordered by any specific value or specifically in the order they were inserted, but in the order that is currently convenient for the database to fetch them. This order may change any time if the database decides on a different execution plan to fetch the data.

If you want a reliable ordering, you need to use the order by clause to specify it.

Guffa
  • 687,336
  • 108
  • 737
  • 1,005
  • Technically mysql supports `ALTER TABLE ... ORDER BY`, but one should understand that it will only work up to the next table modification. – zerkms Nov 03 '14 at 09:37
  • @zerkms I tried this: alter table tablename order by id desc; it does not help. The case is I am reuse our framework to implement a function, it is not a official process, so I don't want to update the select command in the common framework, just want find a work around. – waitsummer Nov 03 '14 at 10:01
  • @waitsumme: well, you haven't explained why you need that. Without that you will not get a meaningful solution for your problem – zerkms Nov 03 '14 at 10:02
  • @waitsummer: you're out of luck – zerkms Nov 03 '14 at 10:10
0

You can try this if you are using phpmyadmin.

Pantamtuy
  • 243
  • 2
  • 13