ORDER BY Clause - Mailing list pgsql-novice

From Derrick Betts
Subject ORDER BY Clause
Date
Msg-id 48017576.6070607@blueaxis.com
Whole thread Raw
Responses Re: ORDER BY Clause  (Frank Bax <fbax@sympatico.ca>)
List pgsql-novice
I have a query: SELECT fruit, group_number, ordering_number FROM
fruit_groups ORDER BY group_number, order_number;

The results look like:
    fruit   |   group_number   |   ordering_number
--------+------------------+-------------------
 cherry  |              1             |              1
 orange |              1             |              2
   apple |              2             |              1
     pear |              2             |              2
 banana |              3             |              1
     kiwi |               3            |              2


I would like the results to look like:
    fruit   |   group_number   |   ordering_number
--------+------------------+-------------------
   apple |              2             |              1
 orange |              2             |              2
 banana |              3             |              1
     kiwi |               3            |              2
 cherry  |              1             |              1
 orange |              1             |               2

I want the group_number to be grouped together, then sorted by the
ordering_number, then listed in the output alphabetically by the fruit
name listed first in the group_number (as defined by the ordering_number).

Does anyone know how I might modify my statement to get this ordering?
Thanks,
Derrick


pgsql-novice by date:

Previous
From: "Jaisen N.D."
Date:
Subject: problem with 8.1: createdb: could not connect to database postgres: could not connect to server: No such file or directory
Next
From: Frank Bax
Date:
Subject: Re: ORDER BY Clause