sulfericacid has asked for the wisdom of the Perl Monks concerning the following question:
You have a mysql database with a column "group". Group can contain nothing, unique values OR shared values with other similar rows of data within the same group.
How would you fetch all of the rows, sort them by the group column and THEN print a header of the group name for each unique group name? For example, the "group" from above would print out:Group SomeData --------------- red 1 yellow 2 green 3 purple 4 red 5 red 6 red 7 orange 8 green 9
The rows should be sorted by "group". Then each "group" has their own header (header would be a prinout of the group itself) which prints before the sql results.Green 3 9 Orange 8 Purple 4 Red 1 5 6 7 Yellow 2
Groups are dynamic so it can't be hard coded.
My idea:
-----------------------
Fetch the rows of the database and store all groups into a hash. Then from there, do a foreach sort and produce a new SQL query for each key.
It seems like this could work but if there's some odd hundred of unique groups, the overhead of all those queries is probably too pricey.
Any ideas or suggestions?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: mysql sorting
by monarch (Priest) on Jun 01, 2005 at 06:06 UTC | |
by perleager (Pilgrim) on Jun 01, 2005 at 07:47 UTC | |
|
Re: mysql sorting
by BrowserUk (Patriarch) on Jun 01, 2005 at 06:01 UTC | |
by jhourcle (Prior) on Jun 01, 2005 at 12:26 UTC | |
by bpphillips (Friar) on Jun 01, 2005 at 13:07 UTC | |
|
Re: mysql sorting
by graff (Chancellor) on Jun 02, 2005 at 02:14 UTC |