Sorting rows alphabetically ?

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
Czar
Forum Commoner
Posts: 58
Joined: Sun Dec 29, 2002 11:17 am

Sorting rows alphabetically ?

Post by Czar »

Just need a query to sort results alphabetically...

SELECT * FROM wpn ORDER BY ?????...

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

Post by twigletmac »

You need to choose which field you want to sort on, for example:

Code: Select all

SELECT first_name, last_name, address, tel_no, email FROM users ORDER BY last_name, first_name
Mac
User avatar
discobean
Forum Commoner
Posts: 49
Joined: Sun May 18, 2003 9:06 pm
Location: Sydney, Australia
Contact:

Post by discobean »

SELECT fieldname1, fieldname2, fieldname3 FROM tablename ORDER BY fieldname1

I would avoid using SELECT * but it dosn't really matter... some db's are faster if u do *, some are slower apparently..
Czar
Forum Commoner
Posts: 58
Joined: Sun Dec 29, 2002 11:17 am

Post by Czar »

Well yeah.. it was a little bit more complex thing than i wrote. Sorry for inconvenience, didn't express myself as i meant to. I had to rearrange result arrays too and grouped em by one more var from db. But did it anyway...

Keep up the GW.
User avatar
cactus
Forum Regular
Posts: 343
Joined: Tue Jun 10, 2003 4:16 am
Location: UK

Post by cactus »

Speed of databases is related to hardware, optimisation, amount of data, database schema, and query tuning to name a few.

Using "SELECT * FROM blah" on a database with a million or so rows and no index would be a little slow, to say the least, and probably halt the server! ;)

Regards,
Post Reply