alrazy1 said:
SELECT u.ID, u.username, u.active, u.email, u.admin,
u.banned, u.name, (SELECT GROUP_CONCAT( g.name SEPARATOR
'-groupsep-' ) FROM groups g, group_memberships gm
WHERE g.ID = gm.group AND gm.user = u.ID ) AS groupmemberships
FROM users u WHERE u.ID={$uid}"
Wow.... that's actually pretty nice. I like it. Anyways, what's happening is that in one table we of course have the users. Another table has the groups. The third table links them, obviously. What it does is say for instance in users there is one user, and in groups there are 4 groups, but user is only in the first 3 groups. this would mean that groupmemberships (gm) has 3 entries:
209432: group1
209432: group2
209432: group3
And lets say user table is something like:
209432: myUserName: true:
User@somewhere.com: False: False: myName
and group table would be something like:
group1: <description>: <member count>: <creation date>: <blah blah>
group2: <description>: <member count>: <creation date>: <blah blah>
group3: <description>: <member count>: <creation date>: <blah blah>
group4: <description>: <member count>: <creation date>: <blah blah>
So this query would concatenate those 3 groups into one row for the user, with a separator of -groupsep-, so it would return this one row:
209432: myUserName, True,
User@somewhere.com: False: False: myName: group1-groupsep-group2-groupsep-group3
At least, that's how I read it. Never used that function ;)
By default though, I believe group_concat would normally use a comma, so it would have been
209432: myUserName, True,
User@somewhere.com: False: False: myName: group1,group2,group3
had SEPERATOR not been used....
Oh and the way it knows which groups to put together is I believe the table (before concat happens) gets grouped by gm.user (user.ID)
That's the best I can make of it. Like I said- I like it. I may use it in fact... I have the perfect query to use that in.....
Hope that helps!
Programmer (n): An organism that can turn caffeine into code.
Programming would be so much easier without all the users.