Think about Loose Coupling | |
PerlMonks |
Perl/SQL query - grouping 'one to many' recordsby pcdj_d (Initiate) |
on Dec 09, 2008 at 23:11 UTC ( [id://729286]=perlquestion: print w/replies, xml ) | Need Help?? |
pcdj_d has asked for the wisdom of the Perl Monks concerning the following question:
I have a situation where I have a table of incidents and a table of actions. The relationship is one incident has many actions. I require the need to display via a web page, a list of incidents IDs and their relevant actions thus: Indicent 1 - Action 1 - Action 2 - Action 3 Indicent 2 - Action 4 Incident 3 - Action 5 - Action 6 Currrently, I just retrieve a set of actions and can sort them by incident ID. However I would like each action grouped by incident, and the incident ID to be displayed just the once before each group of actions. I currently have in one subroutine: And in another subroutine: This will return something along the following lines: 1, 1, Severe, A severe incident 1, 2, Severe, A severe incident 1, 3, Severe, A severe incident 2, 4, Minor, A minor incident 2, 5, Minor, A minor incident I would like something like: 1, Severe, A severe incident -> 1 (action id, with further columns from the action table) -> 2 -> 3 2, Minor, A minor incident -> 4 -> 5 What's the easiest way to do this?
Back to
Seekers of Perl Wisdom
|
|