I'm trying to sort out the results of a tricky select. Each record has the following elements (simplified for clarity):
lastname
amount
category
Let's say my query returns 5 results. They include:
1 category A
1 category B
3 category D
I need to break down my results by category, ordered by name within each category. So my printout might look like:
Category A
Jones $100
Category B
Smith $50
Category D
Martin $10
Riley $20
Thomas $50
So what I need to do is look through my results, find out which categories actually are represented there and print only those categories (I don't want a category heading for "Category C"), and then print the results for each category within.
I guess I could do a separate query of the db for each category, but that seems clunky. Seems like less overhead if I can retrieve ALL the records and then extract them from my $result in some kind of controlled manner.
Any suggestions?