alphabetical order

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

alphabetical order

Post by m3mn0n »

In this new database I created I have to organize some things that require A LOT of cell colums. I inserted all of them into my database from a peice of paper that i had them written on. Now I did the insertions in no special order, but I want now to organize them all in alphabetical order. I'm wondering if this is possible.

I did a search on it but to no preval...

Thanks in advanced. :)
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You can use ORDER BY fieldname to order by a particular field - it'll sort a text field alphabetically.

http://www.mysql.com/doc/en/SELECT.html

But are you trying to permanently reorganise the order?

Mac
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

I could do that for the output which I know how to do, but yea I need to know how to make the changes to the database itself not the output of the database.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

What does the table look like?

You may be able to copy the data to a temp table in the order you want using INSERT...SELECT:
http://www.mysql.com/doc/en/INSERT_SELECT.html
and then delete the old table and rename the copy.

Mac
hedge
Forum Contributor
Posts: 234
Joined: Fri Aug 30, 2002 10:19 am
Location: Calgary, AB, Canada

Post by hedge »

Not sure what you mean. A DB table does not have any order. When you select it back it is essentially random.

It may appear ordered, but won't stay that way when deletes/inserts happen then the deleted rows are re-used by the new inserted rows. Also when the table extends new data could be anywhere on the disk. The only way to guarantee the output order is the order by clause.

edit:

should have said, this is with the db's (Oracle, sybase, etc.) I have used. Maybe some out there do store it in order.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Image

I highlighted the first letters of the coloumns. That is what i want in alphabetical order. It's for organizational reasons, that is just a few of many. I just can't seem to find a way how. :?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Ah, sorry thought you meant you wanted to order the data as opposed to the columns.

Try this:
http://www.mysql.com/doc/en/Change_column_order.html

Mac
hedge
Forum Contributor
Posts: 234
Joined: Fri Aug 30, 2002 10:19 am
Location: Calgary, AB, Canada

Post by hedge »

yep, so did I. Probably have to re-create the table.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

This is nice, very nice. Especially when involving data inside the table but since my table is brand spankin' new, is kinda defeats the whole purpose. :?


:wink: thanks though! =)
Post Reply