SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2004
    Location
    Utah, USA
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    List of groups my users are members of?

    This is probably much simpler than I'm making it out to be but I need a list of my users with a column that shows the name of the group(s) they've joined.

    Here's the schema:

    +---------+-------------+
    | uid | name |
    +---------+-------------+
    | 1 | user 1 |
    | 2 | user 2 |
    | 3 | user 3 |
    | 4 | user 4 |
    | 5 | user 5 |
    +---------+-------------+

    +---------+-------------+
    | gid | name |
    +---------+-------------+
    | 1 | group 1 |
    | 2 | group 2 |
    | 3 | group 3 |
    | 4 | group 4 |
    | 5 | group 5 |
    +---------+-------------+

    +---------+-------------+
    | gid | uid |
    +---------+-------------+
    | 1 | 1 |
    | 2 | 1 |
    | 3 | 4 |
    | 4 | 4 |
    | 5 | 5 |
    +---------+-------------+

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,508
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Code:
    SELECT 
        users.name,
        groups.name
    FROM users
    LEFT OUTER JOIN usergroups
    ON users.uid = usergroups.uid
    LEFT OUTER JOIN groups
    ON usergroups.gid = groups.gid

  3. #3
    SitePoint Zealot
    Join Date
    Aug 2004
    Location
    Utah, USA
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you guido2004!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •