Hi,

Can anyone tell me how to do an mysql query, ordered alphabetically?

Thanks.

    See the MySQL manual page for Sorting Rows. Essentially, you just add an 'ORDER BY' clause to sort the column in ASCending order.

      I took a look at the manuel, but I'm still unsure how I would code the ORDER BY. Is there a special command placed after the ORDER BY that causes the query to order alphabetically?

        Assume that you had a database table called 'letters' that had a-z in a random order (e,q,a,u,b...) in a column called "letter".
        You would use:

        SELECT * FROM `letters` ORDER BY letter ASC
        

        ** Additionally you wouldn't need "ASC" because that is the default order, but is good practice to implement. "DESC" would reverse the sort

        Your structure for coding would be something like:

        SELECT ....
        FROM ....
        WHERE ...
        ORDER BY ...
        LIMIT ...
        

        Just remember "ORDER BY (sort) (order)", where sort is what you want to sort by and order is the way you want to order them.

          Write a Reply...