It appears to me that your usertable looks something like this:
 id     username     branches
  1     vroom        gods,QandA,janitors
  2     merlyn       janitors
  3     Ovid         power users,janitors
  4     dws          power users,janitors,pmdev
This is violating the First Normal Form, which roughly states that no field of a table may contain multiple values. That's why we use Relational Databases in the first place, so that we don't have to use an outside Programming Language to split the values apart. Instead, you make another table, called branch or branches:
 id  name
  1  gods
  2  QandA
  3  janitors
  4  power users
  5  pmdev
Now, if a given user can only belong to one 'branch', then our user table might look like: (2nd Normal Form)
 id     username     branch_id
  1     vroom        1
  2     merlyn       3
  3     Ovid         4
  4     dws          4
If we need to pull out the branches, SQL to the rescue!
SELECT user.username, branch.name FROM user INNER JOIN branch ON user.branch_id = branch.id
However, a given user can belong to multiple branches, so we need employ the 3rd Normal Form. Start by removing the branch_id column from the user table, then create a new table - a 3rd table that will join Users to Branches: (user_branches)
user_id branch_id
   1        1
   1        2
   1        3    (vroom belongs to 1, 2, and 3)
  -------------
   2        3    (merlyn is a janitor)
  -------------
   3        4
   3        3    (Ovid is power user and janitor)
  -------------
   4        4
   4        3
   4        5
The SQL to join all three tables together is trickier, but the more you practice, the better you get. Here it is:
SELECT user.username, branch.name FROM user INNER JOIN user_branches ON user.id = user_branches.user_id INNER JOIN branch ON user_branches.branch_id = branch.id
If you database tables are set up "properly", then you minimize the amount of work you have to do youself in Perl. Let the database do that work for you. :)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to OT: Database table design by jeffa
in thread AoH refs for setting HTML::Template loops by bradcathey

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.