Page 1 of 1

Change the order of database items

Posted: Tue Aug 24, 2010 5:54 am
by badihi
Hello Friends.
How I can change the order of database items.
For example I have a table like this:

[text]Name Email
----------------------------
John john@ex.com
Peter peter@ex.com
Sam sam@ex.com[/text]

Now I want to change the order of this items. For example I want to change the above table to this:

[text]Name Email
----------------------------
Peter peter@ex.com
Sam sam@ex.com
John john@ex.com[/text]

How I can do this?
Thanks!

Re: Change the order of database items

Posted: Tue Aug 24, 2010 9:54 pm
by alex.barylski
Dump the data, re-order the array and re-insert. Alternatively, you can add a field, such as `offset` and in your scripts include an ORDER BY clause to effectively order your result set.

Cheers,
Alex

Re: Change the order of database items

Posted: Wed Aug 25, 2010 3:05 pm
by Gargoyle

Code: Select all

ALTER TABLE [table] ORDER BY eMail DESC

Re: Change the order of database items

Posted: Wed Aug 25, 2010 4:20 pm
by AbraCadaver
Why not just order it when you select it?


[text]SELECT * FROM table_name ORDER BY Email DESC[/text]

Re: Change the order of database items

Posted: Thu Aug 26, 2010 8:04 am
by badihi
Thanks for your replies, friends.
I think that using 'ORDER BY' is the best way. It seems that there is no way to change item's order.
Any way, thanks for your helping! And sorry for my bad English!